title: how to get keys in Map with same sequence as they were inserted
body: <p>I'm trying to put some key values in Map and trying to retrieve them in same sequence as they were inserted. For example below is my code</p>
  
  <pre><code>import java.util.*;
  import java.util.Map.Entry;
  
  public class HashMaptoArrayExample {
  
      public static void main(String args[])
  
      {
     Map&lt;String,Integer&gt; map=  new HashMap&lt;String,Integer&gt;();
  
     // put some values into map
  
     map.put("first",1);
     map.put("second",2);
     map.put("third",3);
     map.put("fourth",4);
     map.put("fifth",5);
     map.put("sixth",6);
     map.put("seventh",7);
     map.put("eighth",8);
     map.put("ninth",9);
  
  
  
      Iterator iterator= map.entrySet().iterator();
         while(iterator.hasNext())
         {
             Entry entry =(Entry)iterator.next();   
             System.out.println(" entries= "+entry.getKey().toString());
         }
  
      }
  }
  </code></pre>
  
  <p>I want to retrieve the keys as below</p>
  
  <pre><code>first second third fourth fifth sixth .....
  </code></pre>
  
  <p>But it's displaying in some random order as below in my output</p>
  
  <pre><code>OUTPUT
  
  ninth eigth fifth first sixth seventh third fourth second
  </code></pre>