Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2008, 11:14 PM
Member
 
Join Date: Mar 2008
Posts: 5
markus-sukram is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-29-2008, 05:27 AM
Member
 
Join Date: Mar 2008
Posts: 2
Vicious is on a distinguished road
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).
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-29-2008, 11:25 PM
Member
 
Join Date: Mar 2008
Posts: 5
markus-sukram is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a hashmap to allow duplicate values? Preethi New To Java 0 02-08-2008 01:35 PM
Collision Detection (Game) mscwd Sun Java Wireless Toolkit 0 01-28-2008 09:34 PM
socket Multithreading - & - Obtaining the IP of a client! bluebarca Networking 1 11-16-2007 11:09 AM
Listener collision on game cachi Java Applets 1 08-07-2007 08:48 AM
how to return values from hashmap oregon New To Java 2 08-01-2007 05:56 PM


All times are GMT +3. The time now is 04:05 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org