Which of the following can be the type for x?
private static void spot(____ x) { x.filter(y -> ! y.isEmpty()) .map(y -> 8) .ifPresent(System.out::println); }
C.
List doesn't have a filter()
method, so Option A is incorrect.
Stream does have filter()
and map()
methods.
Stream doesn't have an ifPresent()
method.
This makes IV incorrect, so Options B and D are incorrect.
Both Collection and String have an isEmpty()
method, so either can be used with the Optional, making Option C the answer.