- 不能保证元素的排列顺序,顺序有可能发生变化。
- 元素可以为null
- hashset保证元素不重复~ (这个面试官很可能会问什么原理,这个跟HashMap有关的哦)
- HashSet,需要谈谈它俩hashcode()和equles()哦~
- 实际是基于HashMap实现的,HashSet 底层使用HashMap来保存所有元素的
看看它的add方法吧~
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
看看它的add方法吧~
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}