Seven Ways to Create a Stream in Java

A Stream is a sequence of elements supporting sequential and parallel aggregate operations. We will see seven ways to create a Stream in Java

August 31, 2020

Three Ways to Sum a Stream of Numbers

In this post, we will see the three ways to sum a stream of numbers (using Java streams). We use the mapToInt, reduce, and collect methods.

June 15, 2020

Java 8 Streams Are Not Completely Lazy

Java 8 streams are lazy. The intermediate operations will not be executed till a terminal operation is invoked. But, Java 8 streams flatMap are not lazy.

January 20, 2020

Collectors toMap Duplicate Key

This post shows the Collectors toMap duplicate key exception and the changes made in Java 9 to improve the exception message to contain the value of the key.

December 2, 2019

Collectors groupingBy with Examples

The Collectors groupingBy is a static utility method in the Collectors class. It is used to group the stream elements by a key. In this blog post, we will look at the Collectors groupingBy with examples.

October 6, 2019

Java 8 Collectors toMap with Examples

In this blog post, I will demonstrate the Java 8 Collectors.toMap method with examples and how it’s used to fold a stream into a map.

September 29, 2019