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

Collection Set&HashSet&TreeSet(HashMap实现,去重特性)

时间:2018-05-17 22:03:30      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:collect   col   技术   param   cal   leave   div   com   dde   

一、HashSet

     1. 虑重功能特性(HashMap实现)

       技术分享图片

    2. put(key) 如果重复返回false

    

  /**
     * Adds the specified element to this set if it is not already present.
     * More formally, adds the specified element <tt>e</tt> to this set if
     * this set contains no element <tt>e2</tt> such that
     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
     * If this set already contains the element, the call leaves the set
     * unchanged and returns <tt>false</tt>.
     *
     * @param e element to be added to this set
     * @return <tt>true</tt> if this set did not already contain the specified
     * element
     */
    public boolean add(E e) {
        return map.put(e, PRESENT)==null;    // 重复返回false
    }

 

Collection Set&HashSet&TreeSet(HashMap实现,去重特性)

标签:collect   col   技术   param   cal   leave   div   com   dde   

原文地址:https://www.cnblogs.com/qishuai/p/9053490.html

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