Traversing a Hashtable

N

Nachiketh

hi,
I want to traverse a Hashtable and chek for a key value which is the
least in the entire Hashtable... i am not able to use the iterator()
method on the hashtable... so if someone can please help me by telling
how exactly can i traverse a Hashtable would be of great help... thx
-nachiketh
 
J

Jacob Dreyer

Nachiketh said:
I want to traverse a Hashtable and chek for a key value which is the
least in the entire Hashtable... i am not able to use the iterator()
method on the hashtable... so if someone can please help me by telling
how exactly can i traverse a Hashtable would be of great help

Hashtable.keySet().iterator()
 
D

David Hilsee

Nachiketh said:
hi,
I want to traverse a Hashtable and chek for a key value which is the
least in the entire Hashtable... i am not able to use the iterator()
method on the hashtable... so if someone can please help me by telling
how exactly can i traverse a Hashtable would be of great help... thx

While you can do this by iterating over the keys, make sure that you aren't
making your life harder by using the wrong container for the job. If you
use TreeMap (optionally synchronized by
Collections.synchronizedSortedMap()), then your entries in the map will be
ordered by their key, and all you have to do is call firstKey() to retrieve
the smallest key.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Hashtable 30
HashTable 26
an array in a hashtable 15
static hashtable with conent? 29
Return HashTable 0
hashtable 9
Copy a Hashtable into object? 2
How can I get the key for a specified value in a HashTable object? 8

Members online

No members online now.

Forum statistics

Threads
474,000
Messages
2,570,248
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top