The same key stored in hashmap is the last to overwrite the previous value. Is there any way to get the value stored first?

  java, question
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 firstKeyTheHash valueTo check if it happenedHash collision, that is, whether the corresponding position is empty, this is no problem. The problem is when it happensHash collisionWhen it does, it compares each one stored in that locationKeyWhether it is equal to the newly deposited, if so, replace it, otherwise, add a value at this position. Obviously, the first two in your codeKeyIs the same, so the back will replace the front.

soHashMapThe time complexity of is notO(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.