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.
Loading...
Related Quiz
- What will be the output of the following code snippet: System.out.println(10 + 20 + "Hello" + 30 + 40);?
- The ________ interface provides methods to retrieve the meta data of the database such as its structure (tables, schemas), the user on the connection, etc.
- How does Java handle overriding methods that throw exceptions?
- The keyword ________ is used to skip the rest of the current loop iteration.
- The class ________ is used to create a text field in JavaFX.