Enum Switch Result with Unused Stream dropWhile
Given: and the code fragment: What is the result? -
- 
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The question tests understanding of intermediate stream operations versus terminal operations, and how a switch statement matches an enum constant.
This question tests the interaction between an unused Stream dropWhile operation and a switch expression on an enum. The page establishes that the intermediate stream operation is discarded and the switch correctly matches the enum value.
Choosing an option based on the dropWhile operation modifying the enum, failing to realize that dropWhile is an intermediate operation whose result is unused.
Community Discussion (4 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
TheArrays.stream(Desig.values).dropWhile(...) call is an intermediate operation on a stream. Because its result is not assigned to a variable or consumed by a terminal operation, it has no effect on the program state. The switch statement evaluates Desig.valueOf("CMO"), which resolves to the CMO enum constant. This matches case CMO, executing System.out.println("Marketing") and printing Marketing.Why the Other Options Are Wrong
Options B and C suggest that the output includes a trailing dash or additional text, which does not align with theprintln("Marketing") statement in the code. Option D, UnDefined, would only be printed if the switch fell through to the default case, which doesn't happen because valueOf("CMO") successfully matches case CMO.Community Comment Notes
Commenters noted that thedropWhile operation is unused. As SrinivasJasti pointed out, "dropWhile operation is unused because the method call is not assigned to a variable or consumed." James2033 provided the reconstructed code showing the switch block, confirming that the stream call is a no-op and the switch directly matches the CMO constant. Official Reference
Exam Strategy
Always check if stream operations are terminal or intermediate. An intermediate operation without a terminal operation or variable assignment does absolutely nothing to the underlying data or program flow.