Java中的集合

Java集合体系
  • Set(接口):代表无序、不可重复的集合
  • List(接口):代表有序、重复的集合
  • Map(接口):代表具有映射关系的集合
  • Queue(接口):代表队列集合
集合类和数组区别
  • 数组元素既可以是基本类型的值,也可以是对象(实际上保存的是对象的引用变量)。
  • 集合里只能保存对象(实际上保存的是对象的引用变量,但通常习惯认为集合里保存的是对象)

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

  • Collection(接口)
  • Map(接口)
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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值