title: ArrayList with returned index on add value
body: <p>I am looking for a java data structure similar to an ArrayList that when I do an add or a push with only a value argument an index will be returned for me automatically. </p>
  
  <p>For example:</p>
  
  <pre><code>ArrayList&lt;String&gt; elements = new ArrayList&lt;String&gt;();
  
  String element = "foo";
  String elementTwo = "bar";
  
  int index1 = elements.add(element); //note this does not exist, i.e. returns bool in api
  int index2 = elements.add(elementTwo);
  
  System.out.println(elements.get(index1)); //would give "foo"
  </code></pre>
  
  <p>I could see writing a wrapper class around ArrayList that manages a counter that is incremented on every add operation and invoking:</p>
  
  <pre><code>ArrayList.add(int index, E element)
  </code></pre>
  
  <p>Do you really need to write a wrapper around ArrayList for this? This seems like something simple enough to be provided out of the box somewhere?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I need the index (key) to be fixed and unique for this usecase. A map was suggested and I agree with that. Does anyone know of a map implementation that gives you an automatically (uniquely) generated key on a value insert? I am just trying to decide if I need to implement my own wrapper for this.</p>