java原始碼解析S
阿新 • • 發佈:2018-12-16
Set
A collection that contains no duplicate elements. More formally, sets contain no pair of elements
e1
ande2
such thate1.equals(e2)
, and at most one null element. As implied by its name, this interface models the mathematical set abstraction. – 不包含重複元素的集合,允許null
主要關注
- HashSet
- TreeSet
- ConcurrentSkipListSet
HashSet
特點: 底層原理就是HashMap,不過Set的元素作為Map的key。所以間接保證Set非重複,不連續,非執行緒安全
TreeSet
特點: 底層原理就是TreeMap,連續,非執行緒安全,TreeMap基於紅黑樹
ConcurrentSkipListSet
特點: 底層原理就是ConcurrentNavigableMap,連續,執行緒安全,執行緒安全的有序的集合,適用於高併發的場景。