What does the following code produce? “`java List list = Arrays.asList(“a”, “b”, “c”); list.stream() .filter(s -> s.equals(“b”)) .findFirst() .ifPresent(System.out::println); “`

Java Professional Hard

Java Professional — Hard

What does the following code produce? “`java List list = Arrays.asList(“a”, “b”, “c”); list.stream() .filter(s -> s.equals(“b”)) .findFirst() .ifPresent(System.out::println); “`

Key points

  • The code filters elements using the `filter` method
  • The `findFirst` method returns the first element of the stream
  • The `ifPresent` method prints the element if it is present

Ready to go further?

Related questions