最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
JDK的Set源碼分析

這篇文章主要介紹“JDK的Set源碼分析”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“JDK的Set源碼分析”文章能幫助大家解決問題。

創(chuàng)新互聯(lián)建站專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、市中網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5網(wǎng)站設(shè)計、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為市中等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

首先,我們看一下HashSet

  1.  private transient HashMap map;

  2.     // Dummy value to associate with an Object in the backing Map

  3.     private static final Object PRESENT = new Object();

可見,他適配了HashMap,那么他的功能是如何委托給HashMap結(jié)構(gòu)的呢?

  1.  public boolean add(E e) {

  2.     return map.put(e, PRESENT)==null;

  3.     }

在hashMap中,我們大多數(shù)時候是用value,但是在set的時候,卻很好的利用了已有類HashMap,他利用了HashMap的key的唯一性來保證存儲在Set中的元素的唯一性;

private static final Object PRESENT = new Object();

是這個HashMap所有key的value,他只是一個形式,而我們真正的數(shù)據(jù)是存在在key中的資源;

我們最后拿到的迭代器也是:

  1.   public Iterator iterator() {

  2.     return map.keySet().iterator();

  3.     }

map的keySet的迭代器;

同理,我們看看LinkedhashMap;

  1.  public LinkedHashSet(int initialCapacity, float loadFactor) {

  2.         super(initialCapacity, loadFactor, true);

  3.     }

  4.     /**

  5.      * Constructs a new, empty linked hash set with the specified initial

  6.      * capacity and the default load factor (0.75).

  7.      *

  8.      * @param   initialCapacity   the initial capacity of the LinkedHashSet

  9.      * @throws  IllegalArgumentException if the initial capacity is less

  10.      *              than zero

  11.      */

  12.     public LinkedHashSet(int initialCapacity) {

  13.         super(initialCapacity, .75f, true);

  14.     }

  15.     /**

  16.      * Constructs a new, empty linked hash set with the default initial

  17.      * capacity (16) and load factor (0.75).

  18.      */

  19.     public LinkedHashSet() {

  20.         super(16, .75f, true);

  21.     }

調(diào)用了父類的構(gòu)造函數(shù);構(gòu)造函數(shù)如下:

  1.     HashSet(int initialCapacity, float loadFactor, boolean dummy) {

  2.     map = new LinkedHashMap(initialCapacity, loadFactor);

  3.     }

生出了LinkedHashMap;

同理,我們一樣可見到treeMap的實現(xiàn):

  1.     private transient NavigableMap m;

  2.     // Dummy value to associate with an Object in the backing Map

  3.     private static final Object PRESENT = new Object();

關(guān)于“JDK的Set源碼分析”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。


網(wǎng)站題目:JDK的Set源碼分析
網(wǎng)址分享:http://fisionsoft.com.cn/article/jiedio.html