
CHEAT SHEET
Constructing Various Collections
List<Integer> list = new ArrayList<Integer>();
Queue<Double> queue = new LinkedList<Double>();
Stack<String> stack = new Stack<String>();
Set<String> words = new HashSet<String>();
Map<String, Integer> counts = new TreeMap<String, Integer>();
Methods Found in ALL collections (Lists, Stacks, Queues, Sets, Maps)
removes all elements of the collection
returns true if the given other collection contains the same elements
returns true if the collection has no elements
returns the number of elements in the collection
returns an array of the elements in this collection
returns a string representation such as "[10, -2, 43]"
Methods Found in both Lists and Sets (ArrayList, LinkedList, HashSet, TreeSet)
adds value to collection (appends at end of list)
returns true if the given value is found somewhere in this collection
returns an Iterator object to traverse the collection's elements
finds and removes the given value from this collection
removes any elements found in the given collection from this one
removes any elements not found in the given collection from this one
inserts given value at given index, shifting subsequent values right
returns first index where given value is found in list (-1 if not found)
returns the value at given index
returns last index where given value is found in list (-1 if not found)
removes/returns value at given index, shifting subsequent values left
replaces value at given index with given value
returns sub-portion at indexes from (inclusive) and to (exclusive)
returns the top value from the stack without removing it
removes the top value from the stack and returns it;
peek/pop throw an EmptyStackException if the stack is empty
places the given value on top of the stack
places the given value at the back of the queue
returns the front value from the queue without removing it;
returns null if the queue is empty
removes the value from the front of the queue and returns it;
throws a NoSuchElementException if the queue is empty