集合类 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);
    }

 

posted @ 2018-01-02 21:38  heapStark  阅读(142)  评论(0编辑  收藏  举报