Hashtable q

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pickle

    #1

    Hashtable q

    When traversing an Enumeration of Hashtable keys, I know that modifying the
    HT can cause problems. But is doing lookups okay? E.g., in the following
    code:

    <assume ht is a reference to a Hashtable object>
    Enumeration e = ht.keys();
    Object o;
    while(e.hasmore ()) {
    o = e.next();
    System.out.prin tln(o + ": " + ht.get(o));
    }

    Is this guaranteed to print out all of the key-value pairs?



  • Oliver Wong

    #2
    Re: Hashtable q

    "pickle" <no@email.com > wrote in message
    news:Y1wqe.1350 6$hg.11385@fe12 .lga...[color=blue]
    > When traversing an Enumeration of Hashtable keys, I know that modifying
    > the
    > HT can cause problems. But is doing lookups okay? E.g., in the following
    > code:
    >
    > <assume ht is a reference to a Hashtable object>
    > Enumeration e = ht.keys();
    > Object o;
    > while(e.hasmore ()) {
    > o = e.next();
    > System.out.prin tln(o + ": " + ht.get(o));
    > }
    >
    > Is this guaranteed to print out all of the key-value pairs?[/color]

    I won't use the word "guarantee" (what if a gamma ray from a distant
    supernova explosion flies through your computer case, randomly scrambling
    the bits in RAM?), but I think this is pretty safe.

    - Oliver


    Comment

    Working...