• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hash Map Query

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
like this


Also, using public instance fields is horrid. make id, x, y private and create accessor and mutator methods.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marie O' Driscoll
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for both replies - Problem solved!

 
reply
    Bookmark Topic Watch Topic
  • New Topic