Java?е?HashMap???
???????????? ???????[ 2014/7/21 10:49:25 ] ??????????????? java
?????????????????????????????????????λ??i??????key?????????????????????????????addEntry(hash?? key?? value?? i)??????
????void addEntry(int hash?? K key?? V value?? int bucketIndex) {
????Entry<K??V> e = table[bucketIndex];
????table[bucketIndex] = new Entry<K??V>(hash?? key?? value?? e);
????if (size++ >= threshold)
????resize(2 * table.length);
????}
??????????μ?????table[i]λ??????????????(??????null??????????????)?????????????μ??????next?С??γ??μ??????
???????????????map??get(key)???????????????put????????????
public V get(Object key) { if (key == null) return getForNullKey(); int hash = hash(key.hashCode()); for (Entry<K??V> e = table[indexFor(hash?? table.length)]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) return e.value; } return null; } |
?????????ж?key == null?? ????true?????????getForNullKey()??????????table[0]??????????????key?????table[0]?????????????
????private V getForNullKey() {
????for (Entry<K??V> e = table[0]; e != null; e = e.next) {
????if (e.key == null)
????return e.value;
????}
????return null;
????}
???????key == null ?false?????????get???????°???????hashCode???hash?????hash??table.length???λ??i??????table[i]?????????ken????????????
int hash = hash(key.hashCode()); for (Entry<K??V> e = table[indexFor(hash?? table.length)]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) return e.value; } return null; |
?????????????Java?????漲????2???????equals???????hashCode?????????????hashCode???equals?????????????hashmap??????Java??????????????????????г????????????????????????????????hashCode??????????2??????equals????????hashcode?????????????2??????????hashmap???????????hashmap?????key????????????hashmap??
????д???????HashMap????????????д???????????????????????HashMap????????????????????涼?У????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11