Sobes.tech
Junior

Tell about the methods of the ArrayList class in Java.

sobes.tech AI

Answer from AI

add(E element): Adds an element to the end of the list. add(int index, E element): Inserts an element at the specified index. addAll(Collection<? extends E> c): Adds all elements from another collection to the end of the list. addAll(int index, Collection<? extends E> c): Inserts all elements from another collection at the specified index. clear(): Removes all elements from the list. contains(Object o): Checks if the list contains the specified element. get(int index): Returns the element at the specified index. indexOf(Object o): Returns the index of the first occurrence of the specified element, or -1 if not found. isEmpty(): Checks if the list is empty. lastIndexOf(Object o): Returns the index of the last occurrence of the specified element, or -1 if not found. remove(int index): Removes the element at the specified index. remove(Object o): Removes the first occurrence of the specified element. removeAll(Collection<?> c): Removes from the list all elements that are also in the specified collection. retainAll(Collection<?> c): Retains only the elements in the list that are also in the specified collection. set(int index, E element): Replaces the element at the specified index. size(): Returns the number of elements in the list. toArray(): Converts the list to an array of objects. toArray(T[] a): Converts the list to an array of the specified type. trimToSize(): Trims the capacity of the ArrayList to the current size.