mapss.put("name", "2"); mapss.put("name", "11"); System.out.println(mapss.get("name"));
For example, if the output is 11, is there any way to get the value of 2?
Previously, remember to store hashmap is to first calculate the hashcode value of key, and if this position is found to be empty, store it in; If it is not empty, a linked list is formed.
Isn’t that the case? Ask the Great God for an explanation
Your understanding is not comprehensive.
HashMapWill use first
Hash valueTo check if it happened
Hash collision, that is, whether the corresponding position is empty, this is no problem. The problem is when it happens
Hash collisionWhen it does, it compares each one stored in that location
KeyWhether it is equal to the newly deposited, if so, replace it, otherwise, add a value at this position. Obviously, the first two in your code
KeyIs the same, so the back will replace the front.
HashMapThe time complexity of is not
O(1)If the collision is “intense”, its performance will be reduced. The solution is to increase the capacity, thus reducing the probability of collision, and the performance will naturally become higher. This is what time for space did.