EN
Java - combine multiple lists
5 points
In this short article we would like to show how to combine multiple lists into one list in Java.
Quick solution:
xxxxxxxxxx
1
import java.util.ArrayList;
2
import java.util.Arrays;
3
import java.util.Collections;
4
import java.util.List;
5
6
public class Example {
7
8
public static void main(String[] args) {
9
10
List<String> a = Arrays.asList("a", "aa");
11
List<String> b = Arrays.asList("b", "bb");
12
List<String> c = Arrays.asList("c", "cc");
13
14
List<String> combinedLists = new ArrayList<>();
15
16
combinedLists.addAll(a);
17
combinedLists.addAll(b);
18
combinedLists.addAll(c);
19
20
System.out.println(combinedLists.toString()); // [a, aa, b, bb, c, cc]
21
}
22
}