title: Is the order of values retrieved from a HashMap the insertion order
body: <p>I am trying figure out the order in which the values in a HashMap are/can be retrieved. Heres the code snippet for the same. </p>
  
  <pre><code>import java.util.HashMap;
  
  public class HashMapExample {
  
     public static void main(String[] args) {
         HashMap&lt;Integer, String&gt; hashmap = new HashMap&lt;Integer, String&gt;();
         hashmap.put(1, "apple" );
         hashmap.put(2, "lemon" );
         hashmap.put(3, "orange" );
         hashmap.put(4, "banana" );
         hashmap.put(5, "litchi" );
         hashmap.put(6, "mango" );
         hashmap.put(7, "papaya" );
  
         System.out.println(hashmap.size());
  
         for (String key : hashmap.values()) {
             System.out.println(key);
         }
     }
  }
  </code></pre>
  
  <h2>output:</h2>
  
  <pre><code>7
  apple
  lemon
  orange
  banana
  litchi
  mango
  papaya
  </code></pre>
  
  <p>The values are printed in the order in which they have been inserted. Is this true in general? I was expecting the values to be printed in an arbitrary order. This is using Java 6.</p>