Java Collection System

  • Set (interface) : Represents an unordered, non-repeatable collection
  • List (interface) : Represents an ordered, repeating collection
  • Map (interface) : Represents a collection with a mapping relationship
  • Queue (interface) : Represents a collection of queues

The difference between a collection class and an array

  • Array elements can be either values of primitive types or objects (in effect, they hold reference variables to objects).
  • Collections can only hold objects (in fact, they hold references to objects, but it’s common to think of collections as objects).

Java’s collection classes derive primarily from two interfaces that are the root interface of the Java collection framework, which in turn contain subinterfaces or implementation classes.

  • Collection (interface)
  • Map (Interface)

The UML diagram is shown below

PantUML grammar
A < | - B / / B inherited A < | C... D //D implements C

Collection

@startuml interface Iterable{ } interface Collection{ } interface Set{ } interface Queue{ } interface List{ } interface SortedSet{ } class HashSet{ } abstract AbstractSet{ } abstract AbstractCollection{ } class ArrayList{ } abstract class AbstractList{ } class Vector{ } interface Deque{ } class PriorityQueue{ } abstract class AbstractQueue{ } class TreeSet{  } interface NavigableSet{ } class LinkedHashSet{ } class LinkedList{ } abstract class AbstractSequentialList{ } class Stack{ } class ArrayDeque{ } Iterable <|-- Collection Collection <|-- Set Collection <|-- Queue Collection <|-- List Set  <|-- SortedSet AbstractSet <|-- HashSet Set <|.. HashSet AbstractCollection <|-- AbstractSet Set <|.. AbstractSet Collection <|.. AbstractCollection AbstractList <|-- ArrayList List <|.. ArrayList AbstractCollection <|-- AbstractList List <|.. AbstractList AbstractList <|-- Vector List <|.. Vector Queue <|-- Deque AbstractQueue <|-- PriorityQueue AbstractCollection <|-- AbstractQueue Queue <|.. AbstractQueue AbstractSet <|-- TreeSet NavigableSet <|.. TreeSet SortedSet <|-- NavigableSet HashSet <|-- LinkedHashSet Set <|.. LinkedHashSet AbstractSequentialList <|-- LinkedList List <|.. LinkedList AbstractList <|-- AbstractSequentialList Vector <|-- Stack AbstractCollection <|-- ArrayDeque Deque <|.. ArrayDeque @enduml

Map

@startuml

interface Map{
  }

class HashMap{
  }

abstract class AbstractMap{
  }

class Hashtable{
  }

abstract class Dictionary{
  }

interface SortedMap{
  }

class LinkedHashMap{
  }

class Properties{
  }

class TreeMap{
  }

interface NavigableMap{
  }

AbstractMap <|-- HashMap
Map <|.. HashMap

Map <|.. AbstractMap

Dictionary <|-- Hashtable
Map <|.. Hashtable

Map <|-- SortedMap

HashMap <|-- LinkedHashMap
Map <|.. LinkedHashMap

Hashtable <|-- Properties

AbstractMap <|-- TreeMap
NavigableMap <|.. TreeMap

SortedMap <|-- NavigableMap

@enduml

For Set, List, Queue and Map, the most commonly used are: HashSet, TreeSet, ArrayList, LinkedList, ArrayDeque, HashMap and TreeMap.