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

Given the following code:
List<String> 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<String> 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.

All Posts

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!