源码
public class LinkedHashSet<E>
extends HashSet<E>
implements Set<E>, Cloneable, java.io.Serializable {
private static final long serialVersionUID = -2851667679971038690L;
public LinkedHashSet(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor, true);
}
public LinkedHashSet(int initialCapacity) {
super(initialCapacity, .75f, true);
}
public LinkedHashSet() {
super(16, .75f, true);
}
public LinkedHashSet(Collection<? extends E> c) {
super(Math.max(2*c.size(), 11), .75f, true);
addAll(c);
}
@Override
public Spliterator<E> spliterator() {
return Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED);
}
}
分析: 继承自HashSet,而hashSet中第五个构造函数就是通过LinkedHashMap初始化的,所以这个LinkedHashSet其实就是跟LinkedHashMap一样是为了实现能够有序访问HashSet而存在的,上面是LinkedHashSet全部代码,上面唯一让我产生困惑的地方就在super(Math.max(2*c.size(), 11), .75f, true);为什么是11,?如果你知道,可以留言告诉我哟,谢谢。