Bird
Raised Fist0

Given the following Kafka Streams code, what will be the output messages after processing?

medium📝 Predict Output Q13 of Q15
Kafka - Streams
Given the following Kafka Streams code, what will be the output messages after processing?
stream.filter(value -> value.length() > 3)
      .map(value -> value.substring(0, 3))

Input messages: ["apple", "cat", "banana", "dog"]
A["cat", "dog"]
B["app", "ban"]
C["apple", "banana"]
D["app", "cat", "ban", "dog"]
Step-by-Step Solution
Solution:
  1. Step 1: Apply filter condition

    Keep messages with length > 3: "apple" (5), "banana" (6). "cat" and "dog" are dropped.
  2. Step 2: Apply map operation

    Take first 3 characters: "apple" -> "app", "banana" -> "ban".
  3. Final Answer:

    ["app", "ban"] -> Option B
  4. Quick Check:

    Filter then map = ["app", "ban"] [OK]
Quick Trick: Filter first, then map to transform filtered messages [OK]
Common Mistakes:
MISTAKES
  • Not filtering before mapping
  • Mapping before filtering
  • Including messages with length ≤ 3

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes