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);
    }

 

相关文章:

  • 2021-12-11
  • 2021-11-26
  • 2021-07-02
  • 2022-01-04
  • 2022-01-01
  • 2022-12-23
  • 2022-03-03
猜你喜欢
  • 2021-10-15
  • 2021-11-21
  • 2022-12-23
  • 2021-10-17
  • 2021-08-01
  • 2021-09-05
  • 2021-09-25
相关资源
相似解决方案