2. A collection — sometimes called a container —
is simply an object that groups multiple
elements into a single unit. Collections are
used to store, retrieve, manipulate, and
communicate aggregate data.
14. Think of an example with ArrayList:
List<String> listA = new ArrayList<>();
listA.add("B");
listA.add("C");
listA.add("D");
listA.add("C");
for (String string : listA) { //Iteration
if (string.equals("C")) {
listA.remove("C"); //ConcurrentModificationExp
}
}
System.out.println(listA);
15. List<String> listA = new CopyOnWriteArrayList<>();
listA.add("B");
listA.add("C");
listA.add("D");
listA.add("C");
for (String string : listA) {
if (string.equals("C")) {
listA.remove("C");
}
}
System.out.println(listA);
19.
Fail-fast - work on live data, but become
invalid when live data is modified
Weakly consistent - work on live data, safe,
reflect updates and deletes, but not inserts
Snapshot - work on a snapshot of the live
data, fast, safe, but possibly stale
20.
21.
first() : E
last() : E
headSet(E toElem) : SortedSet<E>
subSet(E fromElem, E toElem) : SortedSet<E>
tailSet(E fromElem) : SortedSet<E>
comparator() : Comparator<? super E>
22.
pollFirst() : E
pollLast() : E
subSet(E from, boolean inclusive, E to, boolean inclusive) :
NavigableSet<E>
headSet(E to, boolean inclusive) : NavigableSet<E>
tailSet(E from, boolean inclusive) : NavigableSet<E>
ceiling(E e) : E
floor(E e) : E
higher(E e) : E
lower(E e) : E
descendingSet() : NavigableSet<E>
descendingIterator() : Iterator<E>
32. Head:Throws Head: Special Tail: Throws
exception
value
exception
Insert
Remove
Examine
Tail: Special
value
addFirst(e)
offerFirst(e)
addLast(e)
offerLast(e)
removeFirst()
pollFirst()
removeLast()
pollLast()
getLast()
peekLast()
Stack: push
Queue: remove
Stack:pop
getFirst()
Queue: element
Queue: poll
peekFirst()
Queue:peek
Stack:peek
Queue: add
Queue: offer
33. Head
Throws
exception
Insert
addFirst(e)
Stack: push
Special value
Blocks
Time out
offerFirst(e)
putFirst(e)
offerFirst(e,
time,unit)
Queue: add
Queue: offer
takeFirst()
pollFirst(e,
time,unit)
Special value
Blocks
Time out
offerLast(e)
putLast(e)
offerLast(e,
time, unit)
Remove
removeFirst()
pollFirst()
Examine
getFirst()
peekFirst()
Queue: element
Queue:peek
Stack:peek
Tail
Throws
exception
Insert
addLast(e)
Remove
Examine
Queue: remove
Stack: push
removeLast()
Queue: remove
Stack:pop
getLast()
Queue: element
Queue: poll
pollLast()
Queue: poll
peekLast()
Queue:peek
Stack:peek
Queue: put
takeLast()
Queue: offer
pollLast(e,
time, unit)
34.
35.
36.
37. Producers wait for consumers to receive
elements. Useful for message passing. Similar
to a broader version of SynchronousQueue.
hasWaitingConsumer() : boolean
getWaitingConsumerCount() : int
transfer(E e)
tryTransfer(E e) : boolean
tryTransfer(E e, long timeout, TimeUnit unit) :
boolean
38.
39. put(E key, V value) : V
putAll(Map<? extends K, ? extends V> m)
remove(Object key) : V
clear()
containsKey(Object key) : boolean
containsValue(Object value) : boolean
isEmpty() : boolean
size() : int
get(Object key) : V
entrySet() : Set<Map.Entry<K,V>>
keySet() : Set<K>
values() : Collection<V>
40. firstKey() : K
lastKey() : K
headMap(K to) : SortedMap<K, V>
subMap(K from, K to) : SortedMap<K, V>
tailMap(K from) : SortedMap<K, V>
comparator() : Comparator<? super K>
42. putIfAbsent(K key, V value) : V
remove(Object key, Object value) : boolean
replace(K key, V value) : V
replace(K key, V oldValue, V newValue) : boolean