Bird
Raised Fist0

What will be the output of this Kafka Streams code?

medium📝 Predict Output Q5 of Q15
Kafka - Streams
What will be the output of this Kafka Streams code?
var result = stream.filter((k, v) -> v.startsWith("A"))
.map((k, v) -> KeyValue.pair(k, v.length()));
result.foreach((k, v) -> System.out.println(k + ":" + v));

Input records:
{"1":"Apple", "2":"Banana", "3":"Avocado"}
A1:Apple 3:Avocado
B1:5 3:7
C2:6
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Filter records starting with 'A'

    Records with keys "1" (Apple) and "3" (Avocado) pass the filter.
  2. Step 2: Map values to their length

    "Apple" length is 5, "Avocado" length is 7, printed as key:value.
  3. Final Answer:

    1:5 3:7 -> Option B
  4. Quick Check:

    filter by start letter, map to length [OK]
Quick Trick: Filter by condition, map to transform value [OK]
Common Mistakes:
MISTAKES
  • Printing original values instead of lengths
  • Including filtered out records
  • Mixing keys and values in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes