Java – ArrayList

ArrayList:

  • ArrayList is an ordered collection and allow duplicates.
  • ArrayList is index based.
  • Processing elements much faster (index based)
  • Insertions and Deletions are slower (shifting of elements takes time)

Methods:

NameDescription
int size()Returns the number of elements in this list.
boolean add(E e)Appends the specified element to the end of this list
Object remove(int index)Removes the element at the specified position in this list
void clear()Removes all of the elements from this list
void add(int index, E element)Inserts element at the specified position in this list
Object get(int index)Returns the element at the specified position in this list
boolean isEmpty()Returns true if this list contains no elements
Object set(int index, E element)Replaces the element at the specified position in this list with the specified element
boolean contains(Object o)Returns true if this list contains the specified element
int indexOf(Object o)Returns the index of the first occurrence of the specified element, or -1 if this list does not contain the element.
Iterator<Object> iterator()Returns an iterator over the elements in this list
boolean addAll(Collection c)Appends all of the elements in the specified collection to the end of this list
Object  clone()Returns a shallow copy of this ArrayList instance
ListIterator listIterator(int index)Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
Object[] toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element).
Scroll to Top