What will be the result of the following Stream operation: Stream.of("a", "b", "c").filter(e -> e.contains("b")).findFirst();?

  • null
  • a
  • b
  • c
In this Stream operation, we start with a stream of strings "a", "b", and "c". The filter operation filters the elements based on the condition e -> e.contains("b"), which checks if the string contains "b". It will return the first element that matches the condition, which is "b". So, the result of this operation is "b". The findFirst() method returns an Optional, which can be null if no elements match the condition.
Add your answer
Loading...

Leave a comment

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