Bird
Raised Fist0

Identify the error in this Kafka Streams code snippet that tries to filter out empty strings:

medium📝 Debug Q14 of Q15
Kafka - Streams
Identify the error in this Kafka Streams code snippet that tries to filter out empty strings:
stream.filter((k, v) -> v != "")
Afilter() cannot be used on streams
BMissing semicolon at the end
CLambda syntax is incorrect
DUsing '!=' to compare strings instead of .equals()
Step-by-Step Solution
Solution:
  1. Step 1: Check string comparison in Java

    In Java, '!=' compares object references, not string content. Use .equals() to compare strings.
  2. Step 2: Identify the correct fix

    Replace 'value != ""' with '!value.equals("")' to properly filter out empty strings.
  3. Final Answer:

    Using '!=' to compare strings instead of .equals() -> Option D
  4. Quick Check:

    String comparison needs .equals() [OK]
Quick Trick: Use .equals() to compare strings in Java [OK]
Common Mistakes:
MISTAKES
  • Using '==' or '!=' for string content comparison
  • Assuming filter() is invalid on streams
  • Ignoring lambda syntax correctness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes