Member-only story
8 Lesser-Known Java Streams API Features
Less known Java streams features with example
Introducing the Everything Bundle — your one-stop solution to mastering Java, Spring Boot, SQL, acing interviews, and securing certifications!
Introduction
Java Streams provide many out-of-the-box powerful features. In this article, we will look into some of the lesser-used or known features among the developers.
- Stream.ofNullable
This method was introduced in Java 9 and helps filter all the null values from the collection, potentially saving us from null pointer exceptions.
In the example below we have a names list that contains null, which we filter using the Stream.ofNullable method.
[Alice, Bob, Charlie]
2. Stream.iterate()
iterate() method is used for creating infinite streams of sequences. It takes seed and unary function that applies…