Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 8

Given the code fragment:

What is the result?

    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
UtemanOption: B

B is the correct answer

xplorerpjOption: B

B is right answer

minhdevOption: B

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

james2033Option: B

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]

SampsOption: B

B is correct