I am working on an implementation of the BlackBerry j2me Java application that does not have the Collections API. So there is no method entrySet()or class Map.Entry. The only methods available to iterate through mappings a Hashtableare elements()and methods keys().
Can we expect that elements()and keys()return the same number of comparisons in the same order? If so, I can do the following:
Enumeration keys = table.keys();
Enumeration elements = table.elements();
String key, value;
while(keys.hasMoreElements()) {
key = keys.nextElement();
value = elements.nextElement();
}
I would think that this is so, but the documents do not say for sure. If I cannot make this assumption, then I will have to iterate only with the keys:
Enumeration keys = table.keys();
String key, value;
while(keys.hasMoreElements()) {
key = keys.nextElement();
value = table.get(key);
}
Edit: It can be assumed that only one thread has access to the table.