List List Integer

next prev

Java List

List in Java provides the facility to maintain the ordered collection. It contains the index-based methods to insert, update, delete and search the elements. It can have the duplicate elements also. We can also store the null elements in the list.

The List interface is found in the java.util package and inherits the Collection interface. It is a factory of ListIterator interface. Through the ListIterator, we can iterate the list in forward and backward directions. The implementation classes of List interface are ArrayList, LinkedList, Stack and Vector. The ArrayList and LinkedList are widely used in Java programming. The Vector class is deprecated since Java 5.

List Interface declaration

Java List Methods

MethodDescription
void add[int index, E element]It is used to insert the specified element at the specified position in a list.
boolean add[E e]It is used to append the specified element at the end of a list.
boolean addAll[Collection c]It returns true if the list contains all the specified element
int indexOf[Object o]It is used to return the index in this list of the first occurrence of the specified element, or -1 if the List does not contain this element.
E remove[int index]It is used to remove the element present at the specified position in the list.
boolean remove[Object o]It is used to remove the first occurrence of the specified element.
boolean removeAll[Collection c]It is used to remove all the elements from the list.
void replaceAll[UnaryOperator operator]It is used to replace all the elements from the list with the specified element.
void retainAll[Collection c]It is used to retain all the elements in the list that are present in the specified collection.
E set[int index, E element]It is used to replace the specified element in the list, present at the specified position.
void sort[Comparator

Chủ Đề