Return to site

JAVA CERTIFICATION QUESTION: Search stream data using the findFirst, findAny, and anyMatch methods

Streams are complicated. With the right approach, they can be very efficient too.

· java,ocp

Given the following code:

List src = List.of("Java 11", "Exam");

Which code fragment determines if the word “Java” is present in the src list in the most computationally efficient way? Choose one.


List res = List.of();

.peek(v -> { if (v.contains("Java")) res.add(v); })


var a = (res.size() > 0);


var a = -> v.contains("Java")).findAny();


var a = -> v.contains("Java"));


var a =

.filter(v -> v.contains("Java"))


The answer is C.