16
Java Collections Framework Interfaces Quick walk through of interfaces of Collections Framework.

2. Java Collections Framework Interfaces

Embed Size (px)

Citation preview

Page 1: 2. Java Collections Framework Interfaces

Java Collections Framework Interfaces

Quick walk through of interfaces of Collections Framework.

Page 2: 2. Java Collections Framework Interfaces

Interfaces of Collections Framework

• Collection<E> interface– Group of Objects. – Collection aka Container of Objects. – Collection is root interface of Java Collections

Framework. – No direct implementation. – All Collections are Iterable. – No mention of what the Collection is or how

Objects are stored.

Page 3: 2. Java Collections Framework Interfaces

• List<E> interface– List extends Collection. – Ordered (on index) collection. – ArrayList (positional or index access) and

LinkedList (sequential access) are popular implementations.

– Allows duplicates.

Page 4: 2. Java Collections Framework Interfaces

• Set<E> interface– Set extends Collection. – Un-ordered Collection. – HashSet (uses hash function) is popular

implementation. – Duplicates are not allowed. – HashSet TreeSet are popular implementations.

Page 5: 2. Java Collections Framework Interfaces

• SortedSet<E> interface– SortedSet extends Set. – Set whose elements are automatically sorted. – Provides ordering on elements based on

Comparable or Comparator interface.

Page 6: 2. Java Collections Framework Interfaces

• NavigableSet<E> interface– NavigableSet extends SortedSet. – Provides navigation methods reporting closest

matches for given search targets. – It can be traversed in ascending or descending

order.

Page 7: 2. Java Collections Framework Interfaces

• Queue<E> interface– Queue extends Collection. – Used to hold elements prior to processing. – Besides methods inherited from Collection

interface it provides additional insertion, extractions and inspection operations.

– PriorityQueue and LinkedList are popular implementations.

Page 8: 2. Java Collections Framework Interfaces

• Deque<E> interface– Deque extends Queue. – Deque is double ended queue with insertion and

removal of elements from both ends.

Page 9: 2. Java Collections Framework Interfaces

• BlockingQueue<E> interface– BlockingQueue extends Queue. – Waits for queue to become non-empty when

retrieving an element. – And waits for space to become available in queue

when storing an element. – ArrayBlockingQueue and LinkedBlockingQueue are

popular implementation.

Page 10: 2. Java Collections Framework Interfaces

• TransferQueue<E> interface– TransferQueue extends BlockingQueue. – It is type of BlockingQueue in which producers

may wait for consumers to receive elements. – LinkedTransferQueue is popular implementation.

Page 11: 2. Java Collections Framework Interfaces

• Map<K, V> interface– Mapping from keys to values.– Each key can map to at most one value.– Unordered.– Key-Value mappings are depends on Hash Function.– Map cannot contain duplicate keys but can contain

duplicate values.– HashMap<K, V> and LinkedHashMap<k, V> is

popular implementation

Page 12: 2. Java Collections Framework Interfaces

• SortedMap<K, V> interface– SortedMap extends Map. – Mapping in SortedMap are sorted by Key, either

by natural ordering or by Comparator provided.– TreeMap<K, V> is popular implementation.

Page 13: 2. Java Collections Framework Interfaces

• NavigableMap<K, V> interface– NavigableMap extends SortedMap. – Provides navigation methods reporting closest

matches for given search targets. – It can be traversed in ascending or descending

order.– TreeMap<K, V> is popular implementation.

Page 14: 2. Java Collections Framework Interfaces

• ConcurrentMap<K, V> interface– ConcurrentMap extends Map. – Provides thread safety and atomicity guarantees.

ConcurrentHashMap is popular implementation.– ConcurrentHashMap<K, V> is popular

implementation

Page 15: 2. Java Collections Framework Interfaces

• ConcurrentNavigableMap<K, V> interface– ConcurrentNavigableMap extends ConcurrentMap

and NavigableMap. – ConcurrentSkipListMap<K, V> is popular

implementation.

Page 16: 2. Java Collections Framework Interfaces

Thank you.