首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

自各儿动手写写:HashSet、LinkedHashSet源码浅析

2012-10-30 
自己动手写写:HashSet、LinkedHashSet源码浅析这篇文章我只是作为一个简要的分析。?首先可以看看之前写的两

自己动手写写:HashSet、LinkedHashSet源码浅析

这篇文章我只是作为一个简要的分析。

?

首先可以看看之前写的两篇的博文,只要你熟悉了下面这两个类的源码就显得很简单了!

自己动手写写:HashMap源码浅析

自己动手写写:LinkedHashMap源码浅析

?

先来介绍下HashSet吧!

/**                                                                     * Constructs a new, empty linked hash set.  (This package private      * constructor is only used by LinkedHashSet.) The backing              * HashMap instance is a LinkedHashMap with the specified initial       * capacity and the specified load factor.                              *                                                                      * @param      initialCapacity   the initial capacity of the hash map   * @param      loadFactor        the load factor of the hash map        * @param      dummy             ignored (distinguishes this            *             constructor from other int, float constructor.)          * @throws     IllegalArgumentException if the initial capacity is less *             than zero, or if the load factor is nonpositive          */                                                                    HashSet(int initialCapacity, float loadFactor, boolean dummy)          {                                                                          map = new LinkedHashMap<E, Object>(initialCapacity, loadFactor);   }                                                                      

?

?此构造函数的访问权限是default,即同包下可见!LinkedHashSet就是通过此构造函数,通过维护这一个LinkedHashMap来实现的。

热点排行