Showing posts with the label List

How to join two lists in Java?

In this section, we will show you how to join two lists in Java. Following ways can be used to  join two lists in Java: By using Stream concat() method  By using addAll() method By using Apache Commons Collections ListUtils.union()  method Example 1:  Join Two Lists using Stream concat() method Stream.concat() method creates a concatenated stream in which the elements are all the elements of the first stream followed by all the elements of the second stream. The resulting stream is ordered if both of the input streams are ordered, and parallel if either of the input streams is parallel. import java.util.ArrayList ; import java.util.Arrays ; import java.util.List ; import ; import ; public class Main { // Driver code public static void main ( String [] args) { List < String > list1 = new ArrayList< String >( Arrays . asList ( "Java" , "Kotlin"