Collection

Collection

  • A collection in Java is a framework that provides an architecture to store and manipulate a group of objects
CollectionOrderingDuplicatesNull ValuesKey Characteristics
ArrayListOrdered (index)YesYesResizable array and good for random access and iterating
LinkedList (as queue)FIFOYesYesDoubly-linked list
ArrayDeque (as queue)FIFOYesNoResizable array
ArrayDeque (as stack)LIFOYesNoResizable array
PriorityQueueNatural orderingYesNoElements are ordered by default comparator or provided one
TreeSetSortedNoNoElements are sorted and unique
HashSetUnorderedNoYesHashtable based
LinkedHashSetInsertion orderNoYesHashtable and linked list based
TreeMapSortedKeys: No, Values: YesKeys: No, Values: YesRed-Black tree
HashtableUnorderedKeys: No, Values: YesKeys: No, Values: NoLegacy
HashMapUnorderedKeys: No, Values: YesKeys: Once, Values: YesHashtable based (array plus linked list or red-black tree)
LinkedHashMapInsertion orderKeys: No, Values: YesKeys: Once, Values: YesHashtable and linked list based