Member-only story

8 Lesser-Known Java Streams API Features

Less known Java streams features with example

Suraj Mishra
Javarevisited
4 min readMar 3, 2024

--

🚀 Unlock Your Path to Success in Java Interview with the Ultimate Grokking Java and Spring Boot Bundle! 🚀

Introducing the Everything Bundle — your one-stop solution to mastering Java, Spring Boot, SQL, acing interviews, and securing certifications!

>> Grab it while its hot.

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.

  1. 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…

--

--

Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Suraj Mishra
Suraj Mishra

Written by Suraj Mishra

Staff Software Engineer @PayPal ( All opinions are my own and not of my employer )

Responses (5)