HashSet 的底层数据结构?
- 基于HashMap实现。
public HashSet() {
map = new HashMap<>();
}
- 值存放于HashMap的key上。
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
- HashMap的value统一为PRESENT。
private static final Object PRESENT = new Object();
