Given two ArrayLists in Java, the task is to join these ArrayLists.
Input: ArrayList1: [Geeks, For, ForGeeks], ArrayList2: [GeeksForGeeks, A computer portal]
Output: ArrayList: [Geeks, For, ForGeeks, GeeksForGeeks, A computer portal]
Input: ArrayList1: [G, e, e, k, s], ArrayList2: [F, o, r, G, e, e, k, s]
Output: ArrayList: [G, e, e, k, s, F, o, r, G, e, e, k, s]
Approach: ArrayLists can be joined in Java with the help of Collection.addAll() method. This method is called by the destination ArrayList and the other ArrayList is passed as the parameter to this method. This method appends the second ArrayList to the end of the first ArrayList.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Iterating over ArrayLists in Java
- Find common elements in two ArrayLists in Java
- Java String join() with examples
- Ints join() function | Guava | Java
- Differences between wait() and join() methods in Java
- Comparison of yield(), join() and sleep() in Java
- Java Concurrency - yield(), sleep() and join() methods
- Java Guava | Longs.join() method with Examples
- Java Guava | Doubles.join() method with Examples
- Java Guava | Floats.join() method with Examples
- Java Guava | Shorts.join() method with Examples
- Java Guava | Chars.join() method with Examples
- Java Guava | Booleans.join() method with Examples
- isAlive() and join() methods of Thread Class in Java
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java Deprecated API Scanner tool (jdepscan) in Java 9 with Examples
- Java.util.LinkedList.offer(), offerFirst(), offerLast() in Java
- Java.lang.Short toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.