This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Hash Map Query Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Hash Map Query" Watch "Hash Map Query" New topic
Author

Hash Map Query

Marie O' Driscoll
Greenhorn

Joined: Mar 19, 2010
Posts: 11
Hi,

I am editing open source code. A hash map is defined as follows:



Junction is a class with a string id and two float values - x and y. In a subsequent class i need to access the values in the hash map. I have the following but I'm getting NULL values: Can someone please point out how I should retrieve class info from the hash map?



I also tried the following but it didn't work either:



Many thanks in advance
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
like this


Also, using public instance fields is horrid. make id, x, y private and create accessor and mutator methods.

JDBCSupport - An easy to use, light-weight JDBC framework -
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Besides keySet() which returns all the keys, there are also methods values() which returns the values and entrySet() which returns both:
Prefer using either values() if you don't need the keys or entrySet() if you do need the keys inside your loop body. Using entrySet() is faster than using keySet() and get() since you don't need to do a full lookup - the value is already there.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Marie O' Driscoll
Greenhorn

Joined: Mar 19, 2010
Posts: 11
Thanks for both replies - Problem solved!

 
jQuery in Action, 2nd edition
 
subject: Hash Map Query
 
Similar Threads
passing on values from method to method
trying to create markers from hashmap
How to make Date Immutable
how to compare the values in arrays
Constructors