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
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