Java OCA OCP Practice Question 998

Question

Which of the following lambda expressions can fill in the blank?

Choose all that apply

List<String> list = new ArrayList<>(); 
list.removeIf(___________________); 
  • A. s -> s.isEmpty()
  • B. s -> {s.isEmpty()}
  • C. s -> {s.isEmpty();}
  • D. s -> {return s.isEmpty();}
  • E. String s -> s.isEmpty()
  • F. (String s) -> s.isEmpty()


A, D, F.

Note

removeIf() expects a Predicate, which takes a parameter list of one parameter using the specified type.

Options B and C are incorrect because they do not use the return keyword.

It is required inside braces for lambda bodies.

Option E is incorrect because it is missing the parentheses around the parameter list.

This is only optional for a single parameter with an inferred type.




PreviousNext

Related