Given the code fragment:
List str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”);
Predicate test = s -> {
int i = 0;
boolean result = s.contains (“pen”);
System.out.print(i++) + “:”);
return result;
};
str.stream()
.filter(test)
.findFirst()
.ifPresent(System.out ::print);
What is the result?
0 : 0 : pen
0 : 1 : pen
0 : 0 : 0 : 0 : 0 : pen
0 : 1 : 2 : 3 : 4 :
A compilation error occurs.
Submit