HashSet 不重复主要add 方法实现,使用 add 方法找到是否存在元素,存在就不添加,不存在就添加.HashSet 主要是基于HashMap 实现的,HashMap 的key就是 HashSet 的元素,HashSet 基于hash 函数实现元素不重复. 首先看 add 方法: public boolean add(E e) { return map.put(e, PRESENT)==null; } HashMap 的put 方法,map 的 put 方法调用 putVal 方法. pu…