程序员地瓜哥的小屋

Java中的集合

2021-07-02  本文已影响0人  CodingDGSun

Java集合体系

集合类和数组区别

Java的集合类主要由两个接口派生而出,他们是Java集合框架的根接口,这两个接口又包含了一些子接口或实现类。

UML关系图如下所示

PantUML语法
A <|-- B //B继承A
C <|... D //D实现了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
13_01

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
13_02

对于Set、List、Queue、Map四种集合,最常用的分别是:HashSetTreeSetArrayListLinkedListArrayDequeHashMapTreeMap

上一篇下一篇

猜你喜欢

热点阅读