/** * @author lautturi.com * Java example: how to combine multiple collections in java */ import java.util.*; import java.util.stream.Stream; public class Lautturi { public static void main(String[] args) { Collection<Integer> collectionA = new ArrayList<Integer>(); collectionA.add(3); collectionA.add(7); collectionA.add(15); collectionA.add(8); Collection<Integer> collectionB = new ArrayList<Integer>(); collectionB.add(1); collectionB.add(3); collectionB.add(5); collectionB.add(7); Collection<Integer> collectionC = new ArrayList<Integer>(); collectionC.add(2); collectionC.add(4); collectionC.add(6); Stream<Integer> combinedStream = Stream.concat( Stream.concat( collectionA.stream(), collectionB.stream() ), collectionC.stream() ); System.out.println(Arrays.toString(combinedStream.toArray())); } }Source:www.lautturi.com
output:
[3, 7, 15, 8, 1, 3, 5, 7, 2, 4, 6]