Java – ArrayList Class

Java ArrayList Class methods, constructors, variables available in Java 8 release are listed below. We will publish example program on each methods ASAP.

Constructors in Java ArrayList Class

S.No Constructor & Description
1 ArrayList()

Constructs an empty list with an initial capacity of ten.
2 ArrayList(Collection<? extends E> c)

Constructs a list containing the elements of the specified collection, in the order they are returned by the collection’s iterator.
3 ArrayList(int initialCapacity)

Constructs an empty list with the specified initial capacity.

Methods in Java ArrayList Class

S.No Method & Description
1 boolean add(E e)

Appends the specified element to the end of this list.
2 void add(int index, E element)

Inserts the specified element at the specified position in this list.
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.
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.
5 void clear()

Removes all of the elements from this list.
6 Object clone()

Returns a shallow copy of this ArrayList instance.
7 boolean contains(Object o)

Returns true if this list contains the specified element.
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.
9 void forEach(Consumer<? super E> action)

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.
10 E get(int index)

Returns the element at the specified position in this list.
11 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.
12 boolean isEmpty()

Returns true if this list contains no elements.
13 Iterator<E> iterator()

Returns an iterator over the elements in this list in proper sequence.
14 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.
15 ListIterator<E> listIterator()

Returns a list iterator over the elements in this list (in proper sequence).
16 ListIterator<E> listIterator(int index)

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
17 E remove(int index)

Removes the element at the specified position in this list.
18 boolean remove(Object o)

Removes the first occurrence of the specified element from this list, if it is present.
19 boolean removeAll(Collection<?> c)

Removes from this list all of its elements that are contained in the specified collection.
20 boolean removeIf(Predicate<? super E> filter)

Removes all of the elements of this collection that satisfy the given predicate.
21 protected void removeRange(int fromIndex, int toIndex)

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
22 void replaceAll(UnaryOperator<E> operator)

Replaces each element of this list with the result of applying the operator to that element.
23 boolean retainAll(Collection<?> c)

Retains only the elements in this list that are contained in the specified collection.
24 E set(int index, E element)

Replaces the element at the specified position in this list with the specified element.
25 int size()

Returns the number of elements in this list.
26 void sort(Comparator<? super E> c)

Sorts this list according to the order induced by the specified Comparator.
27 Spliterator<E> spliterator()

Creates a late-binding and fail-fast Spliterator over the elements in this list.
28 List<E> subList(int fromIndex, int toIndex)

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
29 Object[] toArray()

Returns an array containing all of the elements in this list in proper sequence (from first to last element).
30 <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.
31 void trimToSize()

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

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Java – DoubleBinaryOperator Interface
  2. Java – ObjDoubleConsumer Interface
  3. Java – SynchronousQueue Class
  4. Java – Locale.Builder Class
  5. Java – IntToDoubleFunction Interface
  6. Java – BiPredicate Interface
  7. Java – BiConsumer Interface
  8. Java – AtomicReferenceArray Class
  9. Java – ToLongBiFunction Interface
  10. Java – DoubleToIntFunction Interface
  11. Java – Phaser Class
  12. Java – ForkJoinWorkerThread Class
  13. Java – Spliterator Interface
  14. Java – BlockingQueue Interface
  15. Java – LockSupport Class

Be the first to comment

Leave a Reply