今儿老师讲hash表是数组和链表的集合,final int hash说通过key去调用hashcode方法通过哈希算法得出的值,而且一个链表的hash值都相同,那么通过一个方法调用,值也相同,那么key就相同呗,然后说hashmap有个get(Object key)的方法得到value的值,那么,key相同hash相同,值也相同嘛,要都相同,这链表还有啥意义啊
CodePudding user response:
Through a method call, with the same value, then the key same bai, this sentence is wrong, the same key value is not necessarily the same, the role of the list is to resolve hash collision is different key, the hash is the same problem, if the key value is different, need to hash the same word in an array of the same location using the method of head form list, after the jdk1.8 in conditions satisfy it could become a red-black tree, if put behind the same key value will replace the old value, the put and get to the key value