collection
group of objects
unordered collection
stores elements without order; can have duplicate elements
bag
an unordered collection that can have duplicate elements
set
an unordered collection without any duplicate elements
HashSet
class that implements the Set interface with a hash table
TreeSet
class that implements the Set interface with a binary search tree
ArrayList
class that implements the List interface with a contiguous block of memory
LinkedList
class that implements the List interface with nodes and references to other nodes
.add(val)
set method that stores a new value [val] in a Set object, provided the element is not already stored in the Set object
duplicates
will not be added with the add method
Set<Integer> hSet = new HashSet<Integer>();
declaration and implementation of a generic Integer hash set [hSet]
Set<Integer> tSet = new TreeSet<Integer>();
declaration and implementation of a generic Integer tree set [tSet]
.size()
set method that returns the number of elements in the Set object
Iterator<Integer> i = hSet.iterator();
declaration and implementation of an iterator object [i] of a generic Integer hash set [hSet]
.next()
iterator method that hops over an element then returns the element that was hopped over
.hasNext()
iterator method that returns true if another element remains in the Collection object and returns false otherwise
.remove()
iterator method that removes the current item referenced by the iterator (before the iterator) and returns true if an element was removed and returns false otherwise
.remove(val)
set method that removes the element [val], if it exists in the Set object
.contains(val)
set method that returns true if the value [val] exists in the Set object and false otherwise
intersection
contains only those elements contained in the first set, as well as the second set
union
contains the elements of the first set and the elements of the second set
set difference
contains all the elements of the first set that are not found in the second set
symmetric difference
contains the elements of the first set and second set except the ones that are contained in both
order
significant in a set difference
map
object that stores a series of keys that point to a series of targets (1 key to 1 target, but possibly multiple keys to 1 target)
Map hMap = new HashMap();
declaration and implementation of a hash map [hMap]
Map tMap = new TreeMap();
declaration and implementation of a tree map [tMap]
.put(k, t)
map method that stores a new key [k] and target [t] in a map object; can be used to replace existing data in a map with the same key (REMAPPING); returns the currently mapped value before replacing the mapping with the new value in its parameter
Map<String, Integer> hMap = new HashMap<String,Integer>();
declaration and implementation of a generic hash map with String keys and Integer targets [hMap]
.get(k)
map method that returns the object that is mapped to by a specific key [k]
.containsKey(k))
map method that returns true if they key [k] exists and false otherwise
.keySet()
map method returns a set of all the keys in a Map object