1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 Exam - Question 8


Given the code fragment:

What is the result?

Show Answer
Correct Answer: B

The code makes use of Java Streams to evaluate various conditions on the specialDays list and outputs the results. The first line of output comes from the allMatch method, which checks if all elements in the stream match the given predicate (equals 'Labour'). This returns false because not all elements in the list are 'Labour'. The second line uses anyMatch to check if any element in the stream matches 'Labour', which is true. The third line uses noneMatch to check if none of the elements match 'Halloween', which is true as 'Halloween' is not in the list. Finally, findFirst returns an Optional describing the first element of the stream, which is 'NewYear'. Therefore, the output is 'false true true Optional[NewYear]'.

Discussion

5 comments
Sign in to comment
SampsOption: B
Feb 10, 2024

B is correct

james2033Option: B
Feb 15, 2024

package q08; import java.util.List; public class Q08 { public static void main(String[] args) { List<String> specialDays = List.of("NewYear", "Valentines", "Spring", "Labour"); System.out.print(specialDays.stream().allMatch(s -> s.equals("Labour"))); System.out.print(" " + specialDays.stream().anyMatch(s -> s.equals("Labour"))); System.out.print(" " + specialDays.stream().noneMatch(s -> s.equals("Halloween"))); System.out.print(" " + specialDays.stream().findFirst()); } } // Result: // false true true Optional[NewYear]

minhdevOption: B
May 5, 2024

*Match returns boolean findFirst returns Optional Result: B is correct

xplorerpjOption: B
Jun 26, 2024

B is right answer

UtemanOption: B
Jul 2, 2024

B is the correct answer