How to convert a List of Lists to a List in Java 8
In this section, we will show you how to convert a List<List<Object>> to a List<Object> in Java 8 using Stream API. Following ways can be used for converting List<List<Object>> to a List<Object> : 1. By using flatMap () method 2. By using forEach () method 3. By using mapMult () method Example 1: Use flatMap () method Java 8 Stream flatMap () method is used to flatten a Stream of collections to a stream of objects. The objects are combined from all the collections in the original Stream. Flattening is referred to as merging multiple collections/arrays into one. import java.util.Arrays ; import java.util.Collections ; import java.util.List ; import java.util.stream.Collectors ; public class Main { // Driver code public static void main ( String [] args) { //Creating List of Lists List < List < String >> listOfLists = Collections . singletonList ( Arrays . asList ( &quo