This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hash Map Query" Watch "Hash Map Query" New topic

Hash Map Query

Marie O' Driscoll

Joined: Mar 19, 2010
Posts: 11

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

Joined: Oct 27, 2005
Posts: 20279

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.

How To Ask Questions How To Answer Questions
Marie O' Driscoll

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

I agree. Here's the link:
subject: Hash Map Query
jQuery in Action, 3rd edition