Hashtable q  
Author Message
pickle





PostPosted: 2005-6-11 14:41:00 Top

java-programmer, 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.println(o + ": " + ht.get(o));
}

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



 
Oliver Wong





PostPosted: 2005-8-13 4:49:00 Top

java-programmer >> Hashtable q "pickle" <email***@***.com> wrote in message
news:Y1wqe.13506$email***@***.com...
> 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.println(o + ": " + ht.get(o));
> }
>
> Is this guaranteed to print out all of the key-value pairs?

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