HashSet简介
2017-04-24 本文已影响20人
加大装益达
HashSet简介
- HashSet是Set接口的实现,不允许元素重复
- 元素不重复是基于HashMap实现
- 非线程安全的
- 不支持通过get(int)获取指定位置的元素,只能通过Iterator方法来获取
源码分析
jdk1.7.0_71
//
空构造 实际是new 一个HashMap
public HashSet() {
map = new HashMap<>();
}
jdk1.7.0_71
//
public HashSet() {
map = new HashMap<>();
}