码迷,mamicode.com
首页 > 其他好文 > 详细

集合类 collection接口 ArrayList

时间:2018-01-02 23:19:01      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:bsp   nal   set集合   lis   object   style   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);
    }

 

集合类 collection接口 ArrayList

标签:bsp   nal   set集合   lis   object   style   set   实现   集合类   

原文地址:https://www.cnblogs.com/heapStark/p/8179282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!