[Java] Combine multiple Lists (Collections)

Prerequisites

You can also join with List :: addAll, but this time we will join with the following conditions.

--You can enter as many lists as you like --The original list is not affected --Do not do new

manner

You can do this by using the flatMap of the Stream API. If you want to replace it with an array, you can do it with .flatMap (Arrays :: stream).

List l1, l2, l3; //Assuming an initialized list

List merged = Stream.of(l1, l2, l3).flatMap(Collection::stream).collect(Collectors.toList());

Recommended Posts

[Java] Combine multiple Lists (Collections)
Combine Java8 lists
Combine arrays in Java
Java string multiple replacement
Compare Lists in Java
Nesting Java Lists together
Java Collections Framework Review Notes
[Java] Multiple OR condition judgment
Operation to connect multiple Streams @Java
[Java & Kotlin] Create multiple selectable RecyclerView
Catch multiple exceptions together in java
[Java] Generate a narrowed list from multiple lists using the Stream API