Java Lists

ArrayList

// Constructors
ArrayList()
ArrayList(Collection<? extends E> c)
ArrayList(int initialCapacity)

// Iterable operator
Iterator<E> iterator()

// Object operator
equals(Object o)
hashCode(Object o)

// Cloneable operator
Object clone()
  Returns a shallow copy of this ArrayList instance.

// Collection operators:
boolean add(E e)
  Appends the specified element to the end of this list.
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.
void clear()
  Removes all of the elements from this list.
boolean contains(Object o)
  Returns true if this list contains the specified element.
boolean containsAll(Collection<?> c)
  Returns true if this collection contains all of the elements in the specified collection.
boolean isEmpty()
  Returns true if this list contains no elements.
int size()
  Returns the number of elements in this list.
boolean remove(Object o)
  Removes the first occurrence of the specified element from this list, if it is present.
boolean removeAll(Collection<?> c)
  Removes all of this collection's elements contained in the specified collection (optional operation).
boolean retainAll(Collection<?> c)
  Retains only the elements in this collection contained in the specified collection (optional operation).
Object[] toArray()
  Returns an array of the elements in this list in proper sequence (from first to last element).
E[] toArray(E[] a)
  Returns an array 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.

// List operators:
void add(int index, E element)
  Inserts the specified element at the specified position in this list.
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.
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.
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.
E set(int index, E element)
  Replaces the element at the specified position in this list with the specified element.
public ListIterator<E> listIterator()
  Returns a (forward) list iterator.
public ListIterator<E> listIterator(int index)
  Returns a (forward) list iterator starting from index.
public List<E> subList(int fromIndex, int toIndex)
  Returns a sublist using the subarray between the two indices.

// specific to ArrayList
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.
void trimToSize()
  Trims the capacity of this ArrayList instance to be the list's current size.

LinkedList

These functions are also defined in LinkedList and have the same meaning as in ArrayList:
add — both versions, addAll — both versions, clear, clone, contains, get, indexOf, isEmpty, lastIndexOf, listIterator — both versions, remove(int), remove(Object), set, size, subList, toArray — both versions
LinkedList()
LinkedList(Collection<? extends E> c)

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.
Iterator<E> descendingIterator()
  Returns an iterator over the elements in this deque in reverse sequential order.
E element()
  Retrieves, but does not remove, the head (first element) of this list.
E getFirst()
  Returns the first element in this list.
E getLast()
  Returns the last element in this list.
ListIterator<E> listIterator(int index)
  Returns a list-iterator of the elements in this list (in proper sequence), 
    starting at the specified position in the list.
boolean offer(E e)
  Adds the specified element as the tail (last element) of this list.
boolean offerFirst(E e)
  Inserts the specified element at the front of this list.
boolean offerLast(E e)
  Inserts the specified element at the end of this list.
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 poll()
  Retrieves and removes the head (first element) of this list
E pollFirst()
  Retrieves and removes the first element of this list, or returns null if this list is empty.
E pollLast()
  Retrieves and removes the last element of this list, or returns null if this list is empty.
E pop()
  Pops an element from the stack represented by this list.
void push(E e)
  Pushes an element onto the stack represented by this list.
E remove()
  Retrieves and removes the head (first element) of this list.
E removeFirst()
  Removes and returns the first element from this list.
boolean removeFirstOccurrence(Object o)
  Removes the first occurrence (head to tail) of the specified element in this list.
E removeLast()
  Removes and returns the last element from this list.
boolean removeLastOccurrence(Object o)
  Removes the last occurrence (head to tail) of the specified element in this list.

ArrayDeque

The ArrayDeque is like an ArrayList with operations more-or-less restricted to the ends of the list. Both ArrayList and ArrayDeque implement the Deque interface, but the ArrayDeque has features that make it less like a list, such as:
  1. the ArrayDeque does not implement the List interface, thus there is no notion of an element's position.
  2. the ArrayDeque does not permit the addition of null elements, thus making the offer (add) and poll (remove) functions more meaningful, since they return null only on empty.
These functions are also defined in ArrayDeque and have the same meaning as in ArrayList:
add(E) not add(E,int), isEmpty, remove(Object), size, toArray — both versions
These functions are also defined in ArrayDeque and have the same meaning as in LinkedList:
addFirst, addLast, descendingIterator, element, getFirst, getLast, iterator, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove(), removeFirst, removeLast, removeFirstOccurrence, removeLastOccurrence
This leaves only three new operations:
ArrayDeque()
ArrayDeque(Collection<? extends E> c)
ArrayDeque(int numElements)

boolean offer(E e)
  Inserts the specified element at the end of this deque.
boolean offerFirst(E e)
  Inserts the specified element at the front of this deque.
boolean offerLast(E e)
  Inserts the specified element at the end of this deque.


© Robert M. Kline