Java collection architecture

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

Collection classes are different from arrays

  • Array elements can be values of primitive types or objects (which actually hold reference variables of objects).
  • Only objects can be held in collections (they actually hold reference variables to objects, but collections are generally thought of as objects)

Java’s collection classes are derived 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 CCopy the code

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 @endumlCopy the code

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
Copy the code

The most commonly used collections of Set, List, Queue, and Map are: HashSet, TreeSet, ArrayList, LinkedList, ArrayDeque, HashMap, and TreeMap.