What is the result?

Given the code fragment:
List<String> str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”);
Predicate<String> 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?

Given the code fragment:
List<String> str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”);
Predicate<String> 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?

A.
0 : 0 : pen

B.
0 : 1 : pen

C.
0 : 0 : 0 : 0 : 0 : pen

D.
0 : 1 : 2 : 3 : 4 :

E.
A compilation error occurs.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


smh

smh

A.
0 : 0 : pen