Indexed addition without IndexOutOfBounds Exception
<p>I have <code>n</code> objects each of them with an identifying number. I get them unsorted but the range of indexes <code>(0, n-1)</code> is used to identify them. I want to access them as fastest as possible. I suppose that an ArrayList would be the best option, I'd add the object with identifier <code>n</code> at the position of the ArrayList with index <code>n</code> by:</p>

<pre><code>list.add(identifier, object);
</code></pre>

<p>The problem is that when I am adding the objects I get an <code>IndexOutOfBounds Exception</code> because I'm adding them unsorted and the <code>size()</code> is smaller although I know that previous positions will also be filled. </p>

<p>Another option is to use a HashMap but I suppose that  this will decrease performance.</p>

<p>Do you know a collection that has the behavior described above?</p>
