• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generic HashMap  RSS feed

 
Manoj Raghuwanshi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a HashMap<String,CustomObject>
I want to itertate through all the elements, is there any clean way to
do that in java5 (i mean without getting the keyset)
 
Paul Clapham
Sheriff
Posts: 22505
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't say what you meant by "elements", and that isn't a term that the API documentation uses, so it's ambiguous. The clean way to iterate through the keys is "keySet().iterator()", which gives you Strings. The clean way to iterate through the values is "values().iterator()", which gives you CustomObjects.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and to do BOTH, entrySet().iterator()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!