This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HasMap iteration

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a map returned from a function.

Now I wish to get the keys and values from this map..

But i dont have any idea about both the keys as well as values...

I can iterate about the map and get all the values using .get(key);

but how shall i get the keys in the first place..

Thanks,
A Kumar
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashMap provides keySet(), values(), and entrySet() that can all be iterated. The last one holds Map.Entry objects with getKey(), getValue(), and setValue().
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can also use this way.

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnks....

Did the way u guys mentioned ...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic