第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

HashMap的keySet()順序問(wèn)題

HashMap的keySet()順序問(wèn)題

陪伴而非守候 2019-03-30 23:19:16
每次都是 put 相同的值,那么 keySet 得到的 Key 的順序都是固定的么?我自己試的確是這樣的,基本確定是固定的,看源碼肯定更清楚了,自己懶。。。我想這個(gè) KeySet 順序取決于 put 時(shí)散列值,這個(gè)散列值和什么相關(guān)呢,會(huì)不會(huì)換臺(tái)機(jī)器或者換個(gè) jdk 版本這個(gè)值就會(huì)有影響呢?
查看完整描述

1 回答

?
白衣染霜花

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊

put 源碼:


public V put(K key, V value) {

    if (key == null)

        return putForNullKey(value);

    int hash = hash(key.hashCode());

    int i = indexFor(hash, table.length);

    for (Entry<K,V> e = table[i]; e != null; e = e.next) {

        Object k;

        if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {

            V oldValue = e.value;

            e.value = value;

            e.recordAccess(this);

            return oldValue;

        }

    }


    modCount++;

    addEntry(hash, key, value, i);

    return null;

}

在 foreach 循環(huán)中,隱式調(diào)用的 nextEntry 源碼:


    final Entry<K,V> nextEntry() {

        if (modCount != expectedModCount)

            throw new ConcurrentModificationException();

        Entry<K,V> e = next;

        if (e == null)

            throw new NoSuchElementException();


        if ((next = e.next) == null) {

            Entry[] t = table;

            while (index < t.length && (next = t[index++]) == null)

                ;

        }

    current = e;

        return e;

    }


查看完整回答
反對(duì) 回復(fù) 2019-04-15
  • 1 回答
  • 0 關(guān)注
  • 369 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)