ArrayList is a resizable-array implementation of the java.util.List interface, a part of the Java Collection Framework

ArrayList has the following attributes

  • Backed by dynamic array data structure, its capacity auto grows internally

  • Allow null and duplicate elements

  • Elements are positioned as their insertion order

  • Zero based integer index, can access (get / insert / replace/ remove) elements by their index

  • Unsynchronized implementation. In multi-threading environment with at least one thread modifies the list, it must be synchronized externally

The below examples give you some basic usages of ArrayList

You can learn using ArrayList in more details with these tutorials

  • Create and Initialize an ArrayList by using its constructors, add and addAll methods

  • Iterate an ArrayList by using for-each loop and Java 8+ forEach(Consumer) method of Iterable interfaces

  • Query an ArrayList including get element by index, get index by element, check if value existing, get size and check if the list is empty

  • Modify an ArrayList by using add methods to add elements into the list, set method to replace element and remove methods to remove element from the list

  • Sort an ArrayList by using ArrayList instance's sort(Comparator) method in conjunction with Comparable and Comparator interfaces to control over the sort order