title: "key-value" pairs collection maintaining order and retrieving by key and by pair index?
body: <p>I'd would like to use a collection of "key - value" pairs:</p>
  
  <ul>
  <li>Which is the base for a <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html" rel="nofollow noreferrer">JTable</a> data model (<a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/table/TableModel.html" rel="nofollow noreferrer">TableModel</a> implementation), so I need to access elements by their index/position (e.g. to implement <code>Object getValueAt(int rowIndex, int columnIndex)</code>). The collection must preserve the order of the elements. An <a href="http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html" rel="nofollow noreferrer">ArrayList</a> would be good for that.</li>
  <li>Which allows to retrieve elements by the value of the key. A <a href="http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html" rel="nofollow noreferrer">HashMap</a> would be good for that.</li>
  </ul>
  
  <p>The closest usable collection I've found is <a href="http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html" rel="nofollow noreferrer">LinkedHashMap</a>. It preserves the order and allows retrieval by key. However the access to an item is not possible by index/position, I must iterate over the items until the good one is found. This is not be time-effective.</p>
  
  <p>Is there a better one than <a href="https://stackoverflow.com/questions/1509391/how-to-get-the-one-entry-from-hashmap-without-iterating#1510023">this one</a>? 
  Thanks.</p>
  
  <hr>
  
  <p>(Question is similar to <a href="https://stackoverflow.com/questions/20285123/best-java-collection-to-store-key-value-pairs-and-access-its-objects-by-index-o">this one</a>, but the solution provided uses the conversion <code>toArray()</code> which is not time-effective. If the set of pairs changes, the conversion needs to be done again.)</p>