ArrayList
Ordered, resizable array implementation. Fast random access, slower insertions or deletions of elements near the lower indexes.
Common methods:
add(E e)- appends element to endget(int index)- retrieves element at indexremove(int index)- removes element at indexsize()- returns number of elementscontains(Object o)- checks if element existsset(int index, E e)- set element at index
LinkedList
Doubly-linked list implementation. Fast insertions/deletions at ends, slower random access.
Common methods:
add(E e)- appends to endaddFirst(E e)/addLast(E e)- adds to front/backremoveFirst()/removeLast()- removes and returns first/lastget(int index)- retrieves element (slow)size()- returns number of elements
ArrayDeque
Resizable array-based double-ended queue. Fast additions/removals at both ends, no capacity restrictions.
Common methods:
addFirst(E e)/addLast(E e)- adds to front/backremoveFirst()/removeLast()- removes and returns first/lastpeekFirst()/peekLast()- views first/last without removingpush(E e)/pop()- stack operations (front of deque)
PriorityQueue
Heap-based priority queue. Elements ordered by natural ordering or custom comparator, not by insertion order.
Common methods:
add(E e)/offer(E e)- inserts elementpoll()- removes and returns smallest elementpeek()- views smallest element without removingremove(Object o)- removes specific elementsize()- returns number of elements
Stack
LIFO (Last-In-First-Out) data structure. Legacy class - ArrayDeque is preferred for stack operations.
Common methods:
push(E e)- adds element to toppop()- removes and returns top elementpeek()- views top element without removingempty()- checks if stack is emptysearch(Object o)- returns 1-based position from top (returns -1 if not found)
Modern alternative: Use ArrayDeque with push(), pop(), and peek() methods.
Queue (Interface)
FIFO (First-In-First-Out) data structure interface. Common implementations: LinkedList, ArrayDeque, PriorityQueue.
Common methods:
add(E e)/offer(E e)- inserts element (offer returns false if fails, add throws exception)remove()/poll()- removes and returns head (poll returns null if empty, remove throws exception)element()/peek()- views head without removing (peek returns null if empty, element throws exception)size()- returns number of elementsisEmpty()- checks if queue is empty
Collections.sort()
Sorts a List in-place. Uses modified mergesort (Timsort), stable, O(n log n).
Usage:
Collections.sort(List<T> list)- sorts using natural orderingCollections.sort(List<T> list, Comparator<T> c)- sorts using custom comparator
Arrays.sort()
Sorts an array in-place. Uses dual-pivot quicksort for primitives, Timsort for objects. O(n log n) average.
Usage:
Arrays.sort(array)- sorts entire arrayArrays.sort(array, fromIndex, toIndex)- sorts rangeArrays.sort(array, Comparator<T> c)- sorts objects with custom comparator