Hi, could someone please show me how to obtain the values in a HashMap with the same key / are in a collision.

Thanks a lot

Printable View

- 03-28-2008, 11:14 PMmarkus-sukramHashMap: Obtaining all values in a collision?
Hi, could someone please show me how to obtain the values in a HashMap with the same key / are in a collision.

Thanks a lot - 03-29-2008, 05:27 AMVicious
Actually,HashMap is composed of Map.Entry<K,V>,so you can see,one key maps one one value.if you use map.put(k1,v1),you can obtain v1 using method map.get(k1).but if you continue useing map.put(k1,v2),this v1 must be covered by v2.sothat you can only obtain v2 if you use the method map.get(k1) once more.So come back to your problem,you could't get all values int a HashMap,but only get the lasted value through map.get(k).

- 03-29-2008, 11:25 PMmarkus-sukram
Thanks for the reply, but I'm not sure I folllow.

"v1 must be covered by v2.sothat you can only obtain v2 if you use the method map.get(k1) once more"

What is meant by covered?

"you could't get all values int a HashMap,but only get the lasted value through map.get(k). "

I have realised that the get method only returns the object that was inserted last in the collision. Are you saying it's not possible? I highly doubt that, it would make the HashMap a useless datastructure.

I have tried to iterate through my whole HashMap, but it gives only the one object value in the collision and carries on to the next key. I must be missing something, I'm hoping somebody can point me in the right direction here.