public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java.io.Serializable { static final long serialVersionUID = -5024744406713321676L;
private transient HashMap<E,Object> map;
// Dummy value to associate with an Object in the backing Map private static final Object PRESENT = new Object();
/** * HashSet默认构造器,很显然是基于HashMap实现的,将v用Object对象填充掉,只用K做存储 */ public HashSet() { map = new HashMap<E,Object>(); }
/** * Collection参数的构造器 */ public HashSet(Collection<? extends E> c) { map = new HashMap<E,Object>(Math.max((int) (c.size()/.75f) + 1, 16)); addAll(c); }
/** * */ public HashSet(int initialCapacity, float loadFactor) { map = new HashMap<E,Object>(initialCapacity, loadFactor); }
/** * */ public HashSet(int initialCapacity) { map = new HashMap<E,Object>(initialCapacity); }