Traversing a Hashtable

Discussion in 'Java' started by Nachiketh, Aug 3, 2004.

  1. Nachiketh

    Nachiketh Guest

    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
     
    Nachiketh, Aug 3, 2004
    #1
    1. Advertising

  2. Nachiketh

    kjc Guest

    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
     
    kjc, Aug 3, 2004
    #2
    1. Advertising

  3. Nachiketh

    Jacob Dreyer Guest

    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()
     
    Jacob Dreyer, Aug 3, 2004
    #3
  4. Nachiketh

    David Hilsee Guest

    "Nachiketh" <> wrote in message
    news:...
    > 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
     
    David Hilsee, Aug 4, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steven
    Replies:
    6
    Views:
    955
    steven
    Aug 27, 2003
  2. Asad

    XML - traversing in VB

    Asad, Apr 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    605
    Matt Berther
    Apr 16, 2004
  3. Replies:
    4
    Views:
    688
  4. =?Utf-8?B?c2xpbV9uYWxkeQ==?=

    traversing a client directory in ASP.NET

    =?Utf-8?B?c2xpbV9uYWxkeQ==?=, May 10, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    828
    Scott M.
    May 12, 2005
  5. thomson
    Replies:
    0
    Views:
    329
    thomson
    Dec 27, 2005
Loading...

Share This Page