1. 程式人生 > >java原始碼解析S

java原始碼解析S

Set

A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction. – 不包含重複元素的集合,允許null

主要關注

  1. HashSet
  2. TreeSet
  3. ConcurrentSkipListSet

HashSet

特點: 底層原理就是HashMap,不過Set的元素作為Map的key。所以間接保證Set非重複,不連續,非執行緒安全

TreeSet

特點: 底層原理就是TreeMap,連續,非執行緒安全,TreeMap基於紅黑樹

ConcurrentSkipListSet

特點: 底層原理就是ConcurrentNavigableMap,連續,執行緒安全,執行緒安全的有序的集合,適用於高併發的場景。