aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 19541
    
  16

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Marie O' Driscoll
Greenhorn

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

 
Consider Paul's rocket mass heater.
 
subject: Hash Map Query
 
Similar Threads
Constructors
trying to create markers from hashmap
passing on values from method to method
how to compare the values in arrays
How to make Date Immutable