Complete the code to filter messages with value greater than 10.
stream.filter(record -> record.value() [1] 10);
The filter should keep records where the value is greater than 10, so we use the > operator.
Complete the code to map each record to its key.
stream.map(record -> record.[1]());value() returns the value, not the key.timestamp() or topic() returns other info.To get the key from a record, use the key() method.
Fix the error in the filter condition to keep records with even values.
stream.filter(record -> record.value() [1] 2 == 0);
/ instead of modulo %.The modulo operator % returns the remainder. To check even numbers, use value() % 2 == 0.
Fill both blanks to create a map of keys to values for records with values greater than 5.
stream.filter(record -> record.value() [1] 5).map(record -> new KeyValue<>(record.[2](), record.value()));
value() instead of key() for the key.We filter records with values greater than 5 using >. Then we map to a KeyValue with the record's key and value.
Fill all three blanks to filter records with values less than 20, map to uppercase keys, and keep values.
stream.filter(record -> record.value() [1] 20).map(record -> new KeyValue<>(record.[2]().[3](), record.value()));
value() instead of key() for the key.toUpperCase() on the key.We filter records with values less than 20 using <. Then map to a KeyValue with the uppercase key and the value.