35. ArrayList functions

35.1. Description

The following is a list of functions available to ArrayList objects.

35.1.1. boolean add(E e)

Appends the specified element to the end of this list.

35.1.2. void add(int index, E element)

Inserts the specified element at the specified position in this list.

35.1.3. boolean addAll(Collection<? extends E> c)

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s Iterator.

35.1.4. boolean addAll(int index, Collection<? extends E> c)

Inserts all of the elements in the specified collection into this list, starting at the specified position.

35.1.5. void clear()

Removes all of the elements from this list.

35.1.6. Object clone()

Returns a shallow copy of this ArrayList instance.

35.1.7. boolean contains(Object o)

Returns true if this list contains the specified element.

35.1.8. void ensureCapacity(int minCapacity)

Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

35.1.9. E get(int index)

Returns the element at the specified position in this list.

35.1.10. int indexOf(Object o)

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

35.1.11. boolean isEmpty()

Returns true if this list contains no elements.

35.1.12. int lastIndexOf(Object o)

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

35.1.13. E remove(int index)

Removes the element at the specified position in this list.

35.1.14. boolean remove(Object o)

Removes the first occurrence of the specified element from this list, if it is present.

35.1.15. protected void removeRange(int fromIndex, int toIndex)

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.

35.1.16. E set(int index, E element)

Replaces the element at the specified position in this list with the specified element.

35.1.17. int size()

Returns the number of elements in this list.

35.1.18. Object[] toArray()

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

35.1.19. <T> T[] toArray(T[] a)

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

35.1.20. void trimToSize()

Trims the capacity of this ArrayList instance to be the list’s current size.