Complete the code to transform each message value to uppercase in a Kafka Streams application.
KStream<String, String> stream = builder.stream("input-topic"); KStream<String, String> transformed = stream.mapValues(value -> value.[1]());
The toUpperCase() method converts the string to uppercase, which is a common transformation in stream processing.
Complete the code to filter messages where the value length is greater than 5.
KStream<String, String> filtered = stream.filter((key, value) -> value.[1]() > 5);
The length() method returns the number of characters in a string, which is used to filter messages by length.
Fix the error in the code to correctly convert the message value to an integer before doubling it.
KStream<String, Integer> doubled = stream.mapValues(value -> Integer.[1](value) * 2);
Integer.parseInt() converts a string to a primitive int, which can then be used in arithmetic operations.
Fill both blanks to create a map of word counts from a stream of sentences.
KTable<String, Long> wordCounts = stream .flatMapValues(value -> Arrays.asList(value.toLowerCase().split(" "))) .groupBy((key, word) -> word) .[1]() .[2]();
The groupByKey() groups the stream by the word key, and count() method counts the occurrences of each word.
Fill all three blanks to filter, transform, and write the stream to an output topic.
stream .filter((key, value) -> value.[1]() > 10) .mapValues(value -> value.[2]()) .to("[3]", Produced.with(Serdes.String(), Serdes.String()));
The code filters messages with values longer than 10 characters, converts them to uppercase, and writes to the output-topic.