title: What is the BEST way to iterate through Hashtable entries WITHOUT the java.lang.Map APIs?
body: <p>I am working on a BlackBerry j2me Java implementation that does not have the Collections API.  So there is no <code>entrySet()</code> method or <code>Map.Entry</code> class.  The only available methods to iterate through the mappings of a <code>Hashtable</code> are the <code>elements()</code> and <code>keys()</code> methods.</p>
  
  <p>Can I expect <code>elements()</code> and <code>keys()</code> to return the same number of mappings, in the same order?  If so, I can do the following:</p>
  
  <pre><code>Enumeration keys = table.keys();
  Enumeration elements = table.elements();
  String key, value;
  while(keys.hasMoreElements()) {
      key = keys.nextElement();
      value = elements.nextElement();
  }
  </code></pre>
  
  <p>I would think this is the case, but the docs don't say for sure.  If I can't make this assumption, then I will have to iterate through the keys only:</p>
  
  <pre><code>Enumeration keys = table.keys();
  String key, value;
  while(keys.hasMoreElements()) {
      key = keys.nextElement();
      // Less efficient b/c I have to do a lookup every time.
      value = table.get(key);
  }
  </code></pre>
  
  <p><strong>Edit:</strong> You can assume only one thread has access to the table.</p>