Understanding Java Streams

The Bored Dev
The Startup
Published in
12 min readJun 24, 2020

--

After having had a deep introduction to functional programming in my last article “A new Java functional style”, I think it’s now time to look at Java Streams more in depth and understand how they work internally. This can be something very important when working with Streams if our performance is going to be impacted.

You’ll be able to see how much easier and efficient is processing sequences of elements with Java Streams compared to the “old way” of doing things and how nice is to write code using fluent interfaces.

You can now say good-bye to error-prone code, full of boilerplate code and clutter that was making our lives as developers much more complicated.

Let’s start by having a brief introduction to Java Streams first!

Java Streams

Introduction

Java Streams are basically a pipeline of aggregate operations that can be applied to process a sequence of elements.

An aggregate operation is a higher-order function that receives a behaviour in a form of a function or lambda, and that behaviour is what gets applied to our sequence.
For example, if we define the following stream:

collection.stream()
.map(element -> decorateElement(element))
.collect(toList())

--

--