Input: Collection = [1, 2, 3]
Output: ArrayList = [1, 2, 3]
Input: Collection = [GFG, Geek, GeeksForGeeks]
Output: ArrayList = [GFG, Geek, GeeksForGeeks]
- Get the Collection whose items are to be added into the ArrayList
- Create an ArrayList
- Add all the items of Collection into this ArrayList using ArrayList.addAll() method
- ArrayList with all the items of Collections have been created.
Below is the implementation of the above approach:
ArrayList with all elements of collection [1, 2, 3]: [1, 2, 3]
ArrayList with all elements of collection [GFG, Geeks, GeeksForGeeks]: [GFG, Geeks, GeeksForGeeks]
- How to add selected items from a collection to an ArrayList in Java?
- Java Collection| Difference between Synchronized ArrayList and CopyOnWriteArrayList
- ArrayList of ArrayList in Java
- Java.util.ArrayList.addall() method in Java
- Garbage Collection in Java
- Iterator vs Collection in Java
- ArrayList in Java
- Arraylist.contains() in Java
- Java.util.Arraylist.indexOf() in Java
- Java.util.ArrayList.add() Method in Java
- Convert an Iterable to Collection in Java
- Difference between Arrays and Collection in Java
- Collection contains() method in Java with Examples
- Collection add() method in Java with Examples
- Randomly select items from a List in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.