集合类框架的常用类比较

集合类框架的常用类比较

用“集合框架”设计软件时,记住该框架四个基本接口的下列层次结构关系会有用处:

Collection 接口是一组允许重复的对象。
Set 接口继承 Collection,但不允许重复。
List 接口继承 Collection,允许重复,并引入位置下标。
Map 接口既不继承 Set 也不继承 Collection, 存取的是键值对
我们以下面这个图表来描述一下常用的集合的实现类之间的区别:

Collection/Map

接口

成员重复性

元素存放顺序(Ordered/Sorted)

元素中被调用的方法

基于那中数据结构来实现的

HashSet

Set

Unique elements

No order

equals()

hashCode()

Hash 表

LinkedHashSet

Set

Unique elements

Insertion order

equals()

hashCode()

Hash 表和双向链表

TreeSet

SortedSet

Unique elements

Sorted

equals()

compareTo()

平衡树(Balanced tree)

ArrayList

List

Allowed

Insertion order

equals()

数组

LinkedList

List

Allowed

Insertion order

equals()

链表

Vector

List

Allowed

Insertion order

equals()

数组

HashMap

Map

Unique keys

No order

equals()

hashCode()

Hash 表

LinkedHashMap

Map

Unique keys

Key insertion order/Access order of entries

equals()

hashCode()

Hash 表和双向链表

Hashtable

Map

Unique keys

No order

equals()

hashCode()

Hash 表

TreeMap

SortedMap

Unique keys

Sorted in key order

equals()

compareTo()

平衡树(Balanced tree)

U2FsdGVkX18k5FHtyms4ii0JPfd+DNL77rvcucak6FyIPMMh6wZqiBEXyS9fucf8
j9oFQjF1oKj6e7Aoi4ZPEuUJlgi4s8+Y1RSQw8sVJAej7SueaVblWkNhSZjQviFF
cLI57rqwfHAnbwPQudq4atet2tLoJhhKKMbWXdVudGbETc13tlOaV+/n9JO+P/lX
JNf6ZNDYOU/ry3FrHTcC8IITYoKPV6U9r7/rEL1CCj5jBUkWUW4Rxg/lVBcbhe9H
7QuJDOAk6TfMtgN7w13L9eznBcPm1B71gj6AcjBCL3gdV1JZ+Px1yq6xeo5ByOAs
B/z1/G77IV3Vke/K4sIacp343kVNPM7dhfHlSganDCYNmIJEVOkAVwLjwTZkg9x3
WFfxdat87Efp8LXfPIFx0zM1tiaiTygwBhCwyF2T957YY9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Lgz/wEBVBL6ts9efO6Dwr5CwSLEhWOp8Gi+9lq1ar/4TFBx
O3ObYPCh59SiWp7tuSLAwg1esKdhpYraa8AcrlmYQMM+KhivaWkDgMV8rKNdiIy4
5N3dwzx77i90PEDy8zaQ6NIIjghQk+As8BJ+lthqClQ=

上一篇:MySQL 表字段唯一性约束设置方法unique


下一篇:「进击Redis」十五、奇妙的 Redis HyperLogLog