The java.util package contains all the classes and interfaces for the Collection framework.
A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following:
These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy.
These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.
These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic—that is, the same method can be used on many different implementations of the appropriate collection interface. In essence, algorithms are reusable functionality.
ArrayList and LinkedList both implement the List interface
ArrayList and LinkedList are linear data structure
ArrayList and LinkedList are dynamic data structure
boolean add(E e) Appends the specified element to the end of this list.
void add(int index, E element) Inserts the specified element at the specified position in this list.
boolean contains(Object o) Returns true if this list contains the specified element.
E get(int index) Returns the element at the specified position in this list.
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.
boolean isEmpty() Returns true if this list contains no elements.
Iterator<E> iterator() Returns an iterator over the elements in this list in proper sequence.
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.
E remove(int index) Removes the element at the specified position in this list.
boolean remove(Object o) Removes the first occurrence of the specified element from this list, if it is present.
E set(int index, E element) Replaces the element at the specified position in this list with the specified element.
int size() Returns the number of elements in this list.
boolean add(E e) Appends the specified element to the end of this list.
void add(int index, E element) Inserts the specified element at the specified position in this list.
void addFirst(E e) Inserts the specified element at the beginning of this list.
void addLast(E e) Appends the specified element to the end of this list.
boolean contains(Object o) Returns true if this list contains the specified element.
E element() Retrieves, but does not remove, the head (first element) of this list.
E get(int index) Returns the element at the specified position in this list.
E getFirst() Returns the first element in this list.
E getLast() Returns the last element in this list.
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.
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.
E peek() Retrieves, but does not remove, the head (first element) of this list.
E peekFirst() Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.
E peekLast() Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.
E remove() Retrieves and removes the head (first element) of this list.
E remove(int index) Removes the element at the specified position in this list.
boolean remove(Object o) Removes the first occurrence of the specified element from this list, if it is present.
E removeFirst() Removes and returns the first element from this list.
boolean removeFirstOccurrence(Object o) Removes the first occurrence of the specified element in this list (when traversing the list from head to tail).
E removeLast() Removes and returns the last element from this list.
boolean removeLastOccurrence(Object o) Removes the last occurrence of the specified element in this list (when traversing the list from head to tail).
E set(int index, E element) Replaces the element at the specified position in this list with the specified element.
int size() Returns the number of elements in this list.