Java OCA OCP Practice Question 1617

Question

Fill in the blank so this code outputs three lines:

List<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");


list.stream().filter(___).forEach(System.out::println);
A.   String::isEmpty
B.   ! String::isEmpty
C.   String::! isEmpty
D.   None of the above


D.

Note

Option A is the only one of the three options to compile.

However, it results in no lines being output since none of the three strings are empty.

Options B and C do not even compile because a method reference cannot have an operator next to it.

Therefore, Option D is correct.




PreviousNext

Related