首页 > 其他 > 详细

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

时间:2018-05-17 21:54:42      阅读:206      评论:0      收藏:0      [点我收藏+]

一、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实现,去重特性)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!