本文的目录结构如下:
还是以官方 javadoc 作为参考进行说明:
LinkedHashSet 没有扩展的属性,直接继承了 HashSet。构造函数都是通过 HashSet 的包级私有构造函数来返回 LinkedHashMap 实例。
/** * Constructs a new, empty linked hash set with the specified initial * capacity and load factor. * 设置 初始容量 和 负载因子 * @param initialCapacity the initial capacity of the linked hash set * @param loadFactor the load factor of the linked hash set * @throws IllegalArgumentException if the initial capacity is less * than zero, or if the load factor is nonpositive */ public LinkedHashSet(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor, true); } /** * Constructs a new, empty linked hash set with the specified initial * capacity and the default load factor (0.75). * 设置 初始容量 和 默认负载因子 * @param initialCapacity the initial capacity of the LinkedHashSet * @throws IllegalArgumentException if the initial capacity is less * than zero */ public LinkedHashSet(int initialCapacity) { super(initialCapacity, .75f, true); } /** * Constructs a new, empty linked hash set with the default initial * capacity (16) and load factor (0.75). * 设置 默认初始容量 和 默认负载因子 */ public LinkedHashSet() { super(16, .75f, true); } /** * Constructs a new linked hash set with the same elements as the * specified collection. The linked hash set is created with an initial * capacity sufficient to hold the elements in the specified collection * and the default load factor (0.75). * * @param c the collection whose elements are to be placed into * this set * @throws NullPointerException if the specified collection is null */ public LinkedHashSet(Collection<? extends E> c) { super(Math.max(2*c.size(), 11), .75f, true); addAll(c); }
和 HashSet 一致,只是内部是 LinkedHashMap 实例在操作,保证有序。不再赘述。
原文:https://www.cnblogs.com/wpbxin/p/12209536.html