Back

Explore Courses Blog Tutorials Interview Questions
0 votes
12 views
in Java by (3.9k points)
If I have a List<List<Object>>, how can I turn that into a List<Object> that contains all the objects in the same iteration order by using the features of Java 8?

1 Answer

0 votes
by (46k points)

You can apply flatMap to flatten the native lists (after converting them to Streams) within a single Stream, and then get the result into a list:

List<List<Object>> list = ...

List<Object> flat = 

    list.stream()

        .flatMap(List::stream)

        .collect(Collectors.toList());

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 2, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...