Skip to main content

Java Run Time in One Table

· 3 min read

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

QueueofferpeekpollremovesizeData 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

Deque

Dequeoffer/offerLastpeekpoll/pollLastremove/removeLastSizeData Structure
LinkedListO(1)O(1)O(1)O(1)O(1)Array
ArrayDequeueO(1)O(1)O(1)O(n)O(1)Linked List

Map

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