public class HashSet<E>{ //重要属性 private transient HashMap<E,Object> map; private static final Object PRESENT = new Object(); //构造器 public HashSet() { map = new HashMap<>();//HashSet底层就是利用HashMap来完成的 } public boolean add(E e) { return map.put(e, PRESENT)==null; } }
标签:map,HashMap,HashSet,private,public,底层 From: https://www.cnblogs.com/jeldp/p/16888414.html