Sheet available for Final
Scanner:
· constructor: Scanner(File source) ; Scanner (String source); Scanner (System.in)
· next() returns next word up to space
· nextLine() returns next line up to line feed
· nextInt() returns next integer up the the line feed
· hasNext() returns true when another word exists in the scanner
· hasNextLine() returns true when another line exists in the scanner
· hasNextInt() returns true when another integer is next in the scanner.
List
· constructor: ArrayList<E> () constructs empty list and ArrayList<E>(Collection c) constructs a list filled with the collection
· constructor: LinkedList<E> () constructs empty list and LinkedList<E>(Collection c) constructs a list filled with the collection
·
get(int
index) Returns the element at the specified position in this list.
set(int index, E element)
Replaces the element at the specified position in this list with the specified
element.
· getIndex(E element) returns the index of the first occurrence of the specified element.
· remove(E element) removes the first occurrence of the specified element
· remove(int index) removes the index and slides all indexes down one
· add(E element) adds the element to the end of the list
· add(int index, E element) inserts that index with that element, pushing all other elements back.
· addall(Collection c) adds all elements of collection c to the end of the List.
· size() returns the number of elements in the array.
Set
· constructor: HashSet<E> () constructs empty list and HashSet<E>(Collection c) constructs a set filled with the collection
· constructor: TreeSet<E> () constructs empty list and TreeSet<E>(Collection c) constructs a set filled with the collection and TreeSet<E>(Comparator cm) constructs an empty set that will sort using the comparator.
· add(E e) Adds the specified element to this set if it is not already present (optional operation).
· remove(Object o) Removes the specified element from this set if it is present (optional operation).
· addAll(Collection<? extends E> c) Adds all of the elements in the specified collection to this set if they're not already present (optional operation).
· removeAll(Collection<?> c) Removes from this set all of its elements that are contained in the specified collection (optional operation).
· retainAll(Collection<?> c) Retains only the elements in this set that are contained in the specified collection (optional operation).
· toArray() Returns an array containing all of the elements in this set.
· size() returns the number of elements in the array.
Map
· constructor HashMap<K,V>() constructs an empty map and TreeMap<E>(Comparator cm) constructs an empty map that will sort keys using the comparator.
· get(Object key) Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
· put(K key, V value) Associates the specified value with the specified key in this map (optional operation).
· remove(Object key) Removes the mapping for a key from this map if it is present (optional operation).
· size() Returns the number of key-value mappings in this map.
· keySet() Returns a Set view of the keys contained in this map.
· values() Returns a Collection view of the values contained in this map.
Stack
· constructor Stack<E> () constructs an empty stack containing elements of type E
· empty() Tests if this stack is empty.
· peek() Looks at the object at the top of this stack without removing it from the stack.
· pop() Removes the object at the top of this stack and returns that object as the value of this function.
· push(E item) Pushes an item onto the top of this stack.
· size( ) returns the number of elements in the stack
Queue – Interface (can fill with any List)
· empty() Tests if this queue is empty.
· peek() Looks at the object at the front of this queue without removing it from the stack.
· remove() Removes the object at the front of this queue and returns that object as the value of this function.
· add(E item) Add an item to the back of this queue
· size( ) returns the number of elements in the queue
Collections – static methods
· binarySearch(List<? extends T> list, T key, Comparator<? super T> c) returns the index of a Search of the specified list for the specified object using the binary search algorithm.
· sort(List<T> list) Sorts the specified list into ascending order, according to the natural ordering of its elements.
· sort(List<T> list, Comparator<? super T> c) Sorts the specified list according to the order induced by the specified comparator.
Arrays– static methods
· asList(T... a) Returns a fixed-size list backed by the specified array.
File
· constructor: File (string filename) creates a File object pointing to the filename. If the path is not given, it will use the bluej project's path.
· canRead() Tests whether the application can read the file denoted by this abstract pathname.
String
· charAt(int index) Returns the char value at the specified index.
· substring(int beginIndex) Returns a new string that is a substring of this string, starting at the beginning index and taking the rest of the string.
· substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string, starting at the beginning index and ending one before the endIndex. The character at the endIndex is not included.
Interfaces you might implement:
Comparator
public interface
Comparator<T>{
int compare(T o1, T 02) ; expects negative if o1 <
o2, 0 if equal and positive if o1 > o2
}
Comparable
public interface
Comparable<T>{
int compareTo(T o1); expects
negative if this less than o1, 0 if equal and positive if this more than o2
}