• Post Reply Bookmark Topic Watch Topic
  • New Topic

how i can get all Key/values of a hashtable without knowing the keys ?  RSS feed

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
thank you for reading my post
how i can get all elemets of a hashtable without knowing the hashtable key values ?
i tried with those enumeration stuff with no luck.

thanks
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raminaa niilian:
Hi
thank you for reading my post
how i can get all elemets of a hashtable without knowing the hashtable key values ?
i tried with those enumeration stuff with no luck.

thanks


Well, you have many options...

1. You can get an enumeration of the keys (with keys()), enumerate through those keys to get the matching values.

2. You can get all the key / values pairs in a set (with entrySet()), iterate through the set.

3. You can get all the keys in a set (with keySet()), iterate through those keys to get the matching values.


You can also get an enumeration of the values (with values()), but that is not very useful if you want the key / value pairs. I would recommend either option 2 or 3, as enumerations are not used much anymore.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!