What is the result?

Given the code fragment:
List<String> colors = Arrays.asList(“red”, “green”, “yellow”);
Predicate<String> test = n – > {
System.out.println(“Searching…”);
return n.contains(“red”);
};
colors.stream()
.filter(c -> c.length() > 3)
.allMatch(test);
What is the result?

Given the code fragment:
List<String> colors = Arrays.asList(“red”, “green”, “yellow”);
Predicate<String> test = n – > {
System.out.println(“Searching…”);
return n.contains(“red”);
};
colors.stream()
.filter(c -> c.length() > 3)
.allMatch(test);
What is the result?

A.
Searching…

B.
Searching…
Searching…

C.
Searching…
Searching…
Searching…

D.
A compilation error occurs.



Leave a Reply 9

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


KashiHide

KashiHide

A

smh

smh

Please explain how did you get A. Thank you.

smh

smh

D
compilation error . code does not compile.
anybody else with same answer?

smh

smh

Sorry for previous answers.
The correct answer is. A. Searching…..

dazladhoyya

dazladhoyya

// Hello, run this code true debugger.
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

// Given the code fragment:
public class Q2 {

public static void main(String[] args) {

List colors = Arrays.asList(“red”, “green”, “yellow”);

Predicate test = n -> {
System.out.println(“Searching…”);
return n.contains(“red”);
};
colors.stream()
.filter(c -> c.length() > 3)
.allMatch(test);

}
}
/*
What is the result?

A.
Searching…

B.
Searching…
Searching…

C.
Searching…
Searching…
Searching…

D.
A compilation error occurs.

http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html
*/

Berti John

Berti John

A. is Correct

D M

D M

Does any body have the working code of all these questions