title: Method to extract all keys from LinkedHashMap into a List
body: <p>I am working with many <code>LinkedHashMap</code> that are either <code>LinkedHashMap&lt;Long, Long&gt;</code>, <code>LinkedHashMap&lt;Long, Double&gt;</code> or <code>LinkedHashMap&lt;Long, Integer&gt;</code>.</p>
  
  <p>My objective is to find or create a method that will return a <code>List&lt;Long&gt;</code> with all the keys in the above <code>LinkedHashMap&lt;Long,...&gt;</code> <strong>in the same order</strong>. The ordering is important which is why I don't think I can use <code>myMap.keySet()</code> which is a <code>Set&lt;Long&gt;</code>. Also, I have many other methods that accept only <code>List&lt;Long&gt;</code> as the input so I would like the desired method to return in that object type so I can continue to use these methods.</p>
  
  <p>Writing a method to return this for, e.g., a <code>LinkedHashMap&lt;Long, Long&gt;</code> is easy enough:</p>
  
  <pre><code>private static List&lt;Long&gt; getLongKeys(LinkedHashMap&lt;Long, Long&gt; target) {
      List&lt;Long&gt; keys = new ArrayList&lt;Long&gt;();
  
      for(Map.Entry&lt;Long, Long&gt; t : target.entrySet()) {
          keys.add(t.getKey());
      }
      return keys;
  }
  </code></pre>
  
  <p>However, then I need to write almost identical methods except for <code>LinkedHashMap&lt;Long, Double&gt;</code> and <code>LinkedHashMap&lt;Long, Integer&gt;</code>.</p>
  
  <p>Is there any way I can generalize the method that I pasted to accept all three types: <code>LinkedHashMap&lt;Long, Long&gt;</code>, <code>LinkedHashMap&lt;Long, Double&gt;</code> or <code>LinkedHashMap&lt;Long, Integer&gt;</code>?</p>