Enum Switch Result with Unused Stream dropWhile
Short answer
A The switch statement matches the CMO enum constant and prints Marketing, while the unused dropWhile stream operation is ignored.
Question
- 
Key Takeaways
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.
Common mistake: Choosing an option based on the dropWhile operation modifying the enum, failing to realize that dropWhile is an intermediate operation whose result is unused.
Expert Analysis
Why the Answer Is Correct
The Arrays.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 the println("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 the dropWhile 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
This link opens the official vendor documentation in a new tab.
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.
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 4 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 4
-
james2033 👍 3 Answered Apackage q33; import java.util.Arrays; public class Q33 { public static void main(String[] args) { Arrays.stream(Desig.values()).dropWhile(s -> s.equals(Desig.CMO)); switch (Desig.valueOf("CMO")) { case CEO -> System.out.println("Executive"); case CMO -> System.out.println("Marketing"); case CFO -> System.out.println("Finance"); case CTO -> System.out.println("Technical"); default -> System.out.println("UnDefined"); } } } // Result: // Marketing
-
SrinivasJasti 👍 1 Answered AThe result of the dropWhile operation is unused because the method call is not assigned to a variable or consumed.
-
supersquax 👍 1A is correct, tested in online compiler.
-
xplorerpj 👍 1 Answered AA is correct answer
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.