ArrayList is part of Collections Framework in Java and is a implementation of List Interface. As opposed to Java Array of fixed size. ArrayList in Java are resizable-arrays and provide various utility methods to perform add, remove, update operations.

Creating a new ArrayList

ArrayList<Integer> myArrayList = new ArrayList<Integer>();

Creating a ArrayList is a bit different as compared to Creating an Array. Since ArrayList can only hold Object data, While creating the ArrayList we are denoting the compiler that this ArrayList will contain Integer data.

Let's look into various utility methods provided in ArrayList Class which we can utilise.

Adding an Element into ArrayList

ArrayList myArrayList = new ArrayList();
myArrayList.add(10);

Removing an Element from ArrayList

ArrayList myArrayList = new ArrayList();
myArrayList.add(10);
myArrayList.remove(10);

Check if ArrayList contains specific element

ArrayList myArrayList = new ArrayList();
myArrayList.add(10);
myArrayList.contains(10);

Comments