Results 1 to 3 of 3
  1. #1
    markus-sukram is offline Member
    Join Date
    Mar 2008
    Posts
    5
    Rep Power
    0

    Default HashMap: 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

  2. #2
    Vicious is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default

    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).

  3. #3
    markus-sukram is offline Member
    Join Date
    Mar 2008
    Posts
    5
    Rep Power
    0

    Default

    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.

Similar Threads

  1. How to make a hashmap to allow duplicate values?
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 01:35 PM
  2. Collision Detection (Game)
    By mscwd in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 01-28-2008, 09:34 PM
  3. Replies: 1
    Last Post: 11-16-2007, 11:09 AM
  4. Listener collision on game
    By cachi in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 08:48 AM
  5. how to return values from hashmap
    By oregon in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •