JAVA - ArrayList

Introduction to ArrayList

Maleesha Thalagala
1 min readJul 19, 2021

“ArrayList” can be found in the ‘java. util’ package and it is a class that can be resizable. As we all know built-in array size cannot be modified. If you want to add/remove an element you have to create a new array. But in ArrayList, you can add and remove elements whenever you want. ArrayList is more flexible than the traditional way and it inherits the AbstractList class and implements the List interface.

Photo by Ari He on Unsplash

Creating an array list and adding items.

Example:

import java.util.ArrayList; public class ArrayListEx{
ArrayList<String> books = new ArrayList<String>(); //Create an ArrayList object
books.add("Harry Potter");
books.add("Sherlock Holmes");
books.add("Famous Five");
books.add("Secret Seven");
System.out.println(books);
}
}

Characteristics of ArrayList

  • The ArrayList class can have duplicate elements and it maintains insertion order.
  • Non synchronized.
  • Allows random access since the array works on an index basis.
  • The ArrayList class extends AbstractList class that implements the List interface.
  • List interface extends the Collection and also iterable interfaces in order of hierarchy.

--

--

Maleesha Thalagala
Maleesha Thalagala

Written by Maleesha Thalagala

Software Engineer | Tech Enthusiast | Writer

No responses yet