wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Hashtable getting value without knowing the key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hashtable getting value without knowing the key" Watch "Hashtable getting value without knowing the key" New topic
Author

Hashtable getting value without knowing the key

Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Hi, Im storing vectors in a hashtable. The key is an unique name. How do I get the value without using the keyname like:
Integer n = (Integer)numbers.get("two");
(numbers is the ht). I would like to key #1, and then key#2 etc. Simple put. Im want to get all my information out of my ht, but Im dont know how. Every code Ive found is depending on that your are aware of your keyname.


/ Sebastian<br />No blog, No homepage, No life?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

The Javadoc APIs are your friend. Have a look at the method keys(), which returns an Enumeration of all the keys in the Hashtable. Better (but more complicated and a bit harder for the novice to understand) is the entrySet() method, which returns a Set full of Map.Entry objects, each one of which contains a single key and a single value from the HashMap.


[Jess in Action][AskingGoodQuestions]
 
Don't get me started about those stupid light bulbs.
 
subject: Hashtable getting value without knowing the key
 
Similar Threads
criteriaFind
better way?
Threads access to object and performance/object in ServletContext: value or reference
Hashtable vs. HashMap
Vector Vs. Hashtable