0 votes
1 view
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 (41k 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());

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...