Java Stream Match and FindFirst Results
Given the code fragment: What is the result? - 
Community Votes
100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
This question tests the return types of Stream match methods (boolean) versus find methods (Optional), alongside the common trap of misjudging predicate logic.
This page analyzes the output of Java Stream methods allMatch, anyMatch, noneMatch, and findFirst on a list of strings. It establishes that the correct result is false true true Optional[NewYear].
Choosing an option that outputs the raw string 'NewYear' instead of 'Optional[NewYear]', or incorrectly evaluating the noneMatch predicate as false.
Community Discussion (5 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
TheallMatch method returns false because not all elements in the list equal "Labour". The anyMatch method returns true because at least one element ("Labour") matches the predicate. The noneMatch method returns true because no elements in the list match the evaluated predicate (e.g., a non-existent string). Finally, findFirst returns an Optional describing the first element, yielding Optional[NewYear]. Concatenating these results produces false true true Optional[NewYear].Why the Other Options Are Wrong
Option A uses integers (0 and 1) instead of booleans, which is incorrect since Java'sMatch methods strictly return boolean. Option C incorrectly assumes noneMatch returns false for the evaluated predicate. Option D incorrectly returns true for allMatch and omits the Optional wrapper for the findFirst result, printing the raw string instead.Community Comment Notes
Commenters confirm the behavior of the Stream methods, noting that "Match returns boolean findFirst returns Optional" as minhdev pointed out. James2033 provided a partial code snippet showing the list and the stream operations, which aligns perfectly with thefalse true true Optional[NewYear] output and validates option B. Official Reference
Exam Strategy
Remember that Stream match methods (allMatch, anyMatch, noneMatch) always return a primitive boolean, while find methods like findFirst return an Optional. Trace the predicate logic carefully for each match method to avoid logical negation errors.