C. The second filter uses the mapped uppercase value correctly
D. The lambda syntax is incorrect
Solution
Step 1: Check filter and map chaining
Chaining multiple filters and maps is allowed in Kafka Streams.
Step 2: Verify lambda syntax and logic
Lambdas use correct syntax and logic: first filter checks start, map uppercases, second filter checks length.
Final Answer:
No error; code is correct -> Option A
Quick Check:
Multiple filters and maps allowed = No error; code is correct [OK]
Hint: Multiple filters and maps can be chained without error [OK]
Common Mistakes:
Thinking multiple filters are disallowed
Confusing lambda syntax with other languages
Assuming map changes variable type incorrectly
5. You want to process a Kafka stream of user names to keep only those starting with 'J' and convert them to lowercase. Which code snippet correctly does this?
hard
A. stream.filter(name -> name.startsWith("J"))
.map(name -> name.toLowerCase())
B. stream.map(name -> name.toLowerCase())
.filter(name -> name.startsWith("J"))
C. stream.filter(name -> name.toLowerCase().startsWith("j"))
.map(name -> name.toUpperCase())
D. stream.map(name -> name.startsWith("J"))
.filter(name -> name.toLowerCase())
Solution
Step 1: Filter names starting with 'J'
Use filter(name -> name.startsWith("J")) to keep only names starting with uppercase 'J'.
Step 2: Map filtered names to lowercase
Apply map(name -> name.toLowerCase()) to convert names to lowercase.
Final Answer:
stream.filter(name -> name.startsWith("J"))
.map(name -> name.toLowerCase()) -> Option A
Quick Check:
Filter first, then map to lowercase [OK]
Hint: Filter first by condition, then map to transform [OK]
Common Mistakes:
Mapping before filtering causing wrong results
Using incorrect lambda syntax
Filtering after changing case causing misses
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.