top of page

ArrayList

An ArrayList is a resizeable array. The difference between an array and an arrayList in java is the size of the array can not be motified but an arrayList can be. 

introArraylIst.PNG

To Create ArrayList

To create an ArrayList is a little different from creating an array. First, you would need to call it using "import java.util.ArrayList;" to make your code be able to use ArrayList. Then in main to create an arrayList you have to say "ArrayList<Type> name = new ArrayList<Type>()".

Capture.PNG

Tools to use for ArrayList


To add to an ArrayList: "name.add(variable);"

​

To get one of the variables in an ArrayList: "name.get(index);"

​

To change variables in an ArrayList: "name.set(index,Variable);".
       

To remove a variable: "name.remove(index);"
        

To Print all the vairables of an ArrayList: 
       for (int i = 0; i < name.size(); i++)
       {
           System.out.println(name.get(i));
       }
 

Capture.PNG
Capture.PNG
bottom of page