How do I join two lists in Java? How do I join two lists in Java? java java

How do I join two lists in Java?


In Java 8:

List<String> newList = Stream.concat(listOne.stream(), listTwo.stream())                             .collect(Collectors.toList());


Off the top of my head, I can shorten it by one line:

List<String> newList = new ArrayList<String>(listOne);newList.addAll(listTwo);


You could use the Apache commons-collections library:

List<String> newList = ListUtils.union(list1, list2);