1. Introduction
In this article, We'll learn about java 8 new Stream API flatMap() method. When to use it and how to use it.
flatMap() method is used to convert or flatten Stream of collections into Stream of collection values by removing the collection.
Removing collection such as List or Set from Stream is called flattening.
FlatMap() is part of Stream Intermediate Operations in Java 8.
Java 8, Stream can hold any type of collections and can be converted into Stream<T> as below.
Stream<List<List<String>>> --> apply flatMap() logic --> Stream<String>
Stream<Set<Set<String>>> --> apply flatMap() logic --> Stream<String>
Stream<List<String>>> --> apply flatMap() logic --> Stream<String>
Stream<List<Object>>> --> apply flatMap() logic --> Stream<Object>