How LinkedHashSet Works Internally in Java | Java Hungry
What is Initial capacity and load factor?
The capacity is the number of buckets(used to store key and value) in the Hash table , and the initial capacity is simply the capacity at the time Hash table is created.
The load factor is a measure of how full the Hash table is allowed to get before its capacity is automatically increased.
http://692088846.iteye.com/blog/2076452
What is Initial capacity and load factor?
The capacity is the number of buckets(used to store key and value) in the Hash table , and the initial capacity is simply the capacity at the time Hash table is created.
The load factor is a measure of how full the Hash table is allowed to get before its capacity is automatically increased.
http://692088846.iteye.com/blog/2076452
Set是通过Map来支持的,Set接口里的所有方法,都委托给内部的Map去实现。
http://zhouyunan2010.iteye.com/blog/1236220- /**
- * LinkedHashSet实际上是基于LinkedHashMap的基础上实现的,
- * LinkedHashSet继承自HashSet,在HashSet中有一构造方法
- * HashSet(int initialCapacity, float loadFactor, boolean dummy)
- * 第三个参数dummy为true时new出了一个LinkedHashMap实例,以Set中的
- * 元素为键,以一个Object的虚假的对象为值,所以HashSet中的元素不可能重复。
- * 以下构造函数dummy都为true
- */
- 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);
- }
- }