How to create ArrayList in Java?
How to create ArrayList in Java?
87
21-Jul-2023
Updated on 22-Jul-2023
Aryan Kumar
22-Jul-2023There are two ways to create an array list in Java:
ArrayList()
constructor. TheArrayList()
constructor creates an empty array list.add()
method. Theadd()
method adds an element to the end of the array list.Here is an example of how to create an array list and add some elements to it:
Output:
Here are some important things to note about creating array lists: