title: Retrieve a value from a datatype in Java using either a key or an index
body: <p>I wish to have a Java datatype which stores key value pairs and allows the value to be retrieved by either the key or an index.</p>
  
  <p>I've rolled my own data type which extends <code>java.util.Dictionary</code> and provides an <code>at</code> function to achieve the ability to retrieve by index.</p>
  
  <pre><code>class DataHash &lt;K,V&gt; extends Dictionary&lt;K,V&gt; {
    private List&lt;K&gt; keyOrder = new ArrayList&lt;K&gt;();
    private Dictionary&lt;K,V&gt; internalDataStore = new Hashtable&lt;K,V&gt;();
  
    @Override
    public V put(K key, V value){
      //guards go here to prevent null, duplicate keys etc.
  
      this.keyOrder.add(key);
      return this.internalDataStore.put(key, value);
    }
  
    @Override
    public V get(K key){
      return this.internalDataStore.get(key);
    }
  
    public V at(int index){
      K key = this.keyOrder.get(index);
      return this.internalDataStore.get(key);
    }
  
    //and other functions to extend dictionary etc.
    //all keeping the keyOrder in sync with the internalDataStore
  }
  </code></pre>
  
  <p>My question for SO is whether there is an existing data type which does this, or a more efficient way to implement this in my custom datatype?</p>