博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java容器源码分析(八)——LinkedHashSet
阅读量:6882 次
发布时间:2019-06-27

本文共 2291 字,大约阅读时间需要 7 分钟。

hot3.png

public class LinkedHashSet
    extends HashSet
    implements Set
, Cloneable, java.io.Serializable {    private static final long serialVersionUID = -2851667679971038690L;    /**     * Constructs a new, empty linked hash set with the specified initial     * capacity and load factor.     *     * @param      initialCapacity the initial capacity of the linked hash set     * @param      loadFactor      the load factor of the linked hash set     * @throws     IllegalArgumentException  if the initial capacity is less     *               than zero, or if the load factor is nonpositive     */    public LinkedHashSet(int initialCapacity, float loadFactor) {        super(initialCapacity, loadFactor, true);    }    /**     * Constructs a new, empty linked hash set with the specified initial     * capacity and the default load factor (0.75).     *     * @param   initialCapacity   the initial capacity of the LinkedHashSet     * @throws  IllegalArgumentException if the initial capacity is less     *              than zero     */    public LinkedHashSet(int initialCapacity) {        super(initialCapacity, .75f, true);    }    /**     * Constructs a new, empty linked hash set with the default initial     * capacity (16) and load factor (0.75).     */    public LinkedHashSet() {        super(16, .75f, true);    }    /**     * Constructs a new linked hash set with the same elements as the     * specified collection.  The linked hash set is created with an initial     * capacity sufficient to hold the elements in the specified collection     * and the default load factor (0.75).     *     * @param c  the collection whose elements are to be placed into     *           this set     * @throws NullPointerException if the specified collection is null     */    public LinkedHashSet(Collection
 c) {        super(Math.max(2*c.size(), 11), .75f, true);        addAll(c);    }}

上面就是LinkedHashSet的全部代码!!!!

继承了HashSet,实现Set,Cloneable,Serializable接口。

代码只有构造函数,调用的是HashSet的构造器:

HashSet(int initialCapacity, float loadFactor, boolean dummy) {    map = new LinkedHashMap<>(initialCapacity, loadFactor);}

HashSet定义了 一个默认访问权限的接口,HashSet本身不使用该接口,只提供给LinkedHashSet使用。

因为HashSet源码在前面已经分析,这里不再重复。

转载于:https://my.oschina.net/u/249693/blog/547323

你可能感兴趣的文章
MongoDB 基础
查看>>
redis分布式集群3种架构方案
查看>>
C++ 编程思想——继承和组合
查看>>
Charles抓包显示乱码解决方法
查看>>
Web前端开发中的MCRV模式(转)
查看>>
VC中的字符串转换宏
查看>>
SVN过滤设置 ...
查看>>
POJ 3185 DFS
查看>>
Nginx服务配置编写
查看>>
H5-BLOB
查看>>
有趣的故事
查看>>
Hadoop安全模式
查看>>
HDFS详细分析一
查看>>
python 基础 9.4 游标
查看>>
es6 modules 和commonjs
查看>>
前后台交互
查看>>
LINQ&EF任我行(二)--LinQ to Object (转)
查看>>
Python之旅.第五章.面向对象
查看>>
Unity坐标系 左手坐标系 图
查看>>
python获取昨日日期
查看>>