集合类 collection接口 Set

Collection接口的另外一种实现为Set集合,主要有两种实现方式一种为HashSet另一种为TreeSet,两种实现都依赖与对应的Map实现类。

代码如下:

    public HashSet() {
        map = new HashMap<>();
    }

    public boolean add(E e) {
        return map.put(e, PRESENT)==null;//    private static final Object PRESENT = new Object();
    }

    public boolean contains(Object o) {
        return map.containsKey(o);
    }
原文地址:https://www.cnblogs.com/heapStark/p/8179282.html