Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Traversing a Hashtable

Reply
Thread Tools

Traversing a Hashtable

 
 
Nachiketh
Guest
Posts: n/a
 
      08-03-2004
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
 
Reply With Quote
 
 
 
 
kjc
Guest
Posts: n/a
 
      08-03-2004
use the keys method on the hashtable.


Nachiketh wrote:
> 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


 
Reply With Quote
 
 
 
 
Jacob Dreyer
Guest
Posts: n/a
 
      08-03-2004
Nachiketh wrote:

> 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()

 
Reply With Quote
 
David Hilsee
Guest
Posts: n/a
 
      08-03-2004
"Nachiketh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.

--
David Hilsee


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
traversing a client directory in ASP.NET =?Utf-8?B?c2xpbV9uYWxkeQ==?= ASP .Net 10 05-12-2005 02:10 AM
Traversing properties with a datagrid nmosafi@gmail.com ASP .Net 4 01-04-2005 04:08 PM
XML - traversing in VB Asad ASP .Net 1 04-16-2004 02:20 AM
Traversing Access types in Modelsim steven VHDL 6 08-27-2003 01:04 PM



Advertisments