Skip to main content

LinkedHashSet

extends HashSet<E> implements Set<E>, Cloneable, java.io.Serializable

拥有 HashSet 的所有性能优势,同时还增加了元素的有序性。相当于特定版本的HashSet 或 LinkedHashMap

  • 构造函数

    /**
* FROM LinkedHashSet
* Constructs a new, empty linked hash set with the default initial
* capacity (16) and load factor (0.75).
*/
public LinkedHashSet() {
super(16, .75f, true);
}


/**
* FROM HashSet
* Constructs a new, empty linked hash set. (This package private
* constructor is only used by LinkedHashSet.) The backing
* HashMap instance is a LinkedHashMap with the specified initial
* capacity and the specified load factor.
*
* @param initialCapacity the initial capacity of the hash map
* @param loadFactor the load factor of the hash map
* @param dummy ignored (distinguishes this
* constructor from other int, float constructor.)
* @throws IllegalArgumentException if the initial capacity is less
* than zero, or if the load factor is nonpositive
*/
HashSet(int initialCapacity, float loadFactor, boolean dummy) {
map = new LinkedHashMap<>(initialCapacity, loadFactor);
}