title: Does an ArrayList created from the keySet() of LinkedHashMap preserves the order of insertion?
body: <p>I get data something like </p>
  
  <blockquote>
    <p>{"Employee 1 of ABC", "ABCX"}, {"Employee 2 of ABC", "ABCY"},
    {"Employee 3 of ABC", "ABCZ"}</p>
  </blockquote>
  
  <p>from database through a <code>RefCursor</code>.</p>
  
  <p>I have a case where I need to preserve the order in which data is read from the database.
  Since my data is kind of 'key-value' ,I thought of using a implementation of <code>Map</code> which is ordered. Hence chose <code>LinkedHashMap</code></p>
  
  <pre><code>//defined as a static map inside a common utlity class
  public class Common{
  public static final LinkedHashMap&lt;String, String&gt; empMap = new   LinkedHashMap&lt;String, String&gt;();
  }
  
  //rs is the resultset
  if (rs != null) {
              while (rs.next()) {
                  key = rs.getString("name_text");
                  value = rs.getString("id");
                  Common.empMap.put(key, value);
              }
  }
  </code></pre>
  
  <p>I have to pass the keys to the client, in the same order in which it was retrieved from the database (Cursor).</p>
  
  <pre><code>List&lt;String&gt; empList = new ArrayList&lt;String&gt;(Common.empMap.keySet());
  </code></pre>
  
  <blockquote>
    <p>keySet() - The documentation says "Returns a Set view of the keys
    contained in this map.            The set is backed by the map, so changes to
    the map are reflected in the set,             and vice-versa"</p>
  </blockquote>
  
  <p>What I expect is that Since <code>ArrayList</code> is also an ordered collection, I should get the keys in the same way in which it was retrieved/inserted into the <code>Map</code>. </p>
  
  <p>When I do a sample test program, I am getting as expected.</p>
  
  <pre><code>public class LinkedMap {    
      public static void main(String[] args) {
          LinkedHashMap&lt;String, String&gt; map = new LinkedHashMap&lt;String, String&gt;();        
          map.put("Employee 1 of ABC", "ABCX");
          map.put("Employee 2 of ABC", "ABCY");
          map.put("Employee 3 of ABC", "ABCZ");   
          ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;(map.keySet());   
          System.out.println(list);   
      }
  }
  </code></pre>
  
  <blockquote>
    <p>output:   [Employee 1 of ABC, Employee 2 of ABC, Employee 3 of ABC]</p>
  </blockquote>
  
  <p>However my <strong>question</strong> is , if this is guaranteed output or is it that I am getting just randomly, and it might vary(?),</p>
  
  <ul>
  <li>update 09/14/2019</li>
  </ul>
  
  <p>I am separating the answer from the question to avoid any confusion.</p>