Skip to main content

Complexity

Big O performance - Java Collections.

List

ListAddRemoveGetContainsNextData Structure
ArrayListO(1)O(n)O(1)O(n)O(1)Array
LinkedListO(1)O(1)O(n)O(n)O(1)Linked List
CopyOnWriteArrayListO(n)O(n)O(1)O(n)O(1)Array

Set

SetAddRemoveContainsNextSizeData Structure
HashSetO(1)O(1)O(1)O(h/n)O(1)Hash Table
LinkedHashSetO(1)O(1)O(1)O(1)O(1)Hash Table + Linked List
EnumSetO(1)O(1)O(1)O(1)O(1)Bit Vector
TreeSetO(log n)O(log n)O(log n)O(log n)O(1)Red-black tree
CopyOnWriteArraySetO(n)O(n)O(n)O(1)O(1)Array
ConcurrentSkipListSetO(log n)O(log n)O(log n)O(1)O(n)Skip List

Queue

QueueOfferPeakPollRemoveSizeData Structure
PriorityQueueO(log n)O(1)O(log n)O(n)O(1)Priority Heap
LinkedListO(1)O(1)O(1)O(1)O(1)Array
ArrayDequeueO(1)O(1)O(1)O(n)O(1)Linked List
ConcurrentLinkedQueueO(1)O(1)O(1)O(n)O(n)Linked List
ArrayBlockingQueueO(1)O(1)O(1)O(n)O(1)Array
PriorirityBlockingQueueO(log n)O(1)O(log n)O(n)O(1)Priority Heap
SynchronousQueueO(1)O(1)O(1)O(n)O(1)None!
DelayQueueO(log n)O(1)O(log n)O(n)O(1)Priority Heap
LinkedBlockingQueueO(1)O(1)O(1)O(n)O(1)Linked List

Map

MapGetContainsKeyNextData Structure
HashMapO(1)O(1)O(h / n)Hash Table
LinkedHashMapO(1)O(1)O(1)Hash Table + Linked List
IdentityHashMapO(1)O(1)O(h / n)Array
WeakHashMapO(1)O(1)O(h / n)Hash Table
EnumMapO(1)O(1)O(1)Array
TreeMapO(log n)O(log n)O(log n)Red-black tree
ConcurrentHashMapO(1)O(1)O(h / n)Hash Tables
ConcurrentSkipListMapO(log n)O(log n)O(1)Skip List