If I have a List
, how can I turn that into a >
List
that contains all the objects in the same iteration order
We can use flatmap for this, please refer below code :
List i1= Arrays.asList(1, 2, 3, 4);
List i2= Arrays.asList(5, 6, 7, 8);
List> ii= Arrays.asList(i1, i2);
System.out.println("List>"+ii);
List flat=ii.stream().flatMap(l-> l.stream()).collect(Collectors.toList());
System.out.println("Flattened to List"+flat);