Set.HashSet

HashSet

  • Set實現Collections接口,內部持有HashMap實例,全部操做都藉助於Map
public HashSet() {
        map = new HashMap<>();
}
//private static final Object PRESENT = new Object();
public boolean add(E e) {
        return map.put(e, PRESENT)==null;
}
public Iterator<E> iterator() {
        return map.keySet().iterator();
}
相關文章
相關標籤/搜索