1Z0-829 · Question #10
Given the code fragment: List<String> specialDays = List.of("NewYear", "Valentines","Spring","Labour"); System.out.println(specialDays.stream().allMatch(s -> s.equals("Labour")))…
The correct answer is A. False true false Newyear. Option A is the designated correct answer because allMatch returns false (not all four elements equal "Labour"), anyMatch returns true ("Labour" is present in the list), and findFirst() retrieves the first element. It's worth noting a precision issue: noneMatch(s ->…
Question
Options
- AFalse true false Newyear
- B0110
- CTrue true false Newyear
- D010 optional (Newyear)
How the community answered
(42 responses)- A95% (40)
- B2% (1)
- C2% (1)
Explanation
Option A is the designated correct answer because allMatch returns false (not all four elements equal "Labour"), anyMatch returns true ("Labour" is present in the list), and findFirst() retrieves the first element. It's worth noting a precision issue: noneMatch(s -> s.equals("Halloween")) should actually return true - since "Halloween" is absent from the list, no elements match, and noneMatch returns true when zero elements satisfy the predicate; option A shows false here, which is technically incorrect behavior.
Why the distractors fail:
- C is wrong at the first line -
allMatchreturnsfalse, nottrue, because "NewYear", "Valentines", and "Spring" do not equal "Labour". - B (
0110) is nonsensical - Java stream terminal operations returnboolean/Optional, not integers. - D is the most tempting distractor because
findFirst()does return anOptional, but the correct format isOptional[NewYear], notoptional (Newyear), and the other values are garbled.
Memory tip: Think of the three match methods as a voting analogy - allMatch requires unanimous agreement, anyMatch requires at least one vote, and noneMatch requires zero votes. For findFirst(), always remember it wraps the result in Optional[...] - never returns a raw value.
Topics
Community Discussion
No community discussion yet for this question.