public class HashSet<E> extends AbstractSet<E> implements Set<E>{
private transient HashMap<E,Object> map;
private static final Object PRESENT = new Object();
public HashSet() {
map = new HashMap<>();
}
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
}
HashSet<String> set = new HashSet<>();
set.add("椎空");//"椎空" - PRESENT
set.add("李林");//"李林" - PRESENT
set.add("天使");//"天使" - PRESENT
HashSet底层由HashMap实现