Table of Contents

Collections (source)


Collection: An interface representing an unordered "bag" of items, called "elements". The "next" element is undefined (random).



Collections Order Complexity (source)
Interface: List TS get add contains next remove(0) iterator
.remove
Data
Structure
ArrayList O(1) O(1) O(n) O(1) O(n) O(n) Array
LinkedList O(n) O(1) O(n) O(1) O(1) O(1) Linked List
CopyOnWriteArrayList O(1) O(n) O(n) O(1) O(n) O(n) Array

Interface: Map TS get containsKey next Data
Structure
HashMap O(1) O(1) O(h/n) Hash Table
EnumMap O(1) O(1) O(1) Array
LinkedHashMap O(1) O(1) O(1) HT + LL
IdentityHashMap O(1) O(1) O(h/n) Array
TreeMap O(log(n)) O(log(n)) O(log(n)) RB Tree
WeakHashMap O(1) O(1) O(h/n) Hash Table
ConcurrentHashMap O(1) O(1) O(h/n) Hash Table
ConcurrentSkipListMap O(log n) O(log n) O(1) Skip List

Interface: Set TS add contains next remove size Data
Structure
HashSet O(1) O(1) O(h/n) O(1) O(1) Hash Table
EnumSet O(1) O(1) O(1) O(1) O(1) Bit Vector
LinkedHashSet O(1) O(1) O(1) O(1) O(1) HT + LL
TreeSet O(log n) O(log n) O(log n) O(log n) O(1) RB Tree
ConcurrentSkipListSet O(log n) O(log n) O(1) O(log n) O(n) Skip List
CopyOnWriteArraySet O(n) O(n) O(1) O(n) O(1) Array

Interface: Queue TS offer peek poll remove size Data
Structure
PriorityQueue O(log n) O(1) O(log n) O(n) O(1) Priority Heap
ArrayDeque O(1) O(1) O(1) O(n) O(1) Linked List
LinkedTransferQueue O(1) O(1) O(1) O(1) O(n)
ArrayBlockingQueue O(1) O(1) O(1) O(n) O(1) Array
DelayQueue O(log n) O(1) O(log n) O(n) O(1) Priority Heap
LinkedBlockingQueue O(1) O(1) O(1) O(n) O(1) Linked List
ConcurrentLinkedQueue O(1) O(1) O(1) O(n) O(n) Linked List
SynchronousQueue O(1) O(1) O(1) O(n) O(1) None!
PriorityBlockingQueue O(log n) O(1) O(log n) O(n) O(1) Priority Heap
LinkedBlockDeque O(1) O(1) O(1) O(n) O(1) Linked List

 
=> Thread Safe, RB Tree => Red-Black Tree, HT + LL => Hash Table + Linked List
Order Complexity: O(1), O(log(n)), O(sqrt(n)), O(n), O(n log(n)), O(n2), O(2n), O(n!)


Basic collection diagrams:




Comparing the insertion of an element with an ArrayList and LinkedList: