Creating a list of objects in Java
<p>So I was thinking of creating a list of objects like this</p>

<pre><code>ArrayList&lt;Obj&gt; lst = new ArrayList&lt;Obj&gt;(10);
for (int i = 0; i &lt; 10; i++) {
  Obj elem = new Obj();
  lst.add(elem);
}
</code></pre>

<p>Is this legal or do I have to worry about Object 1 getting trashed when the elem reference starts pointing to Object 2?  If it's illegal, how might I do it otherwise?  Is there a way to automatically generate ten different reference names?</p>
