2d arraylists in java (why are the collections the same eventually)
<p>i'm new in java and in stackoverflow too. I just have a 2d arrayList. An arrayList which has inside (10) arrayLists. The code i tried is the following:</p>

<p>2d arrayList inside the main arrayList there are 10 arrayLists</p>

<pre><code> ArrayList&lt;ArrayList&lt;Items&gt;&gt; arrayList = new ArrayList&lt;ArrayList&lt;Items&gt;&gt;();
</code></pre>

<p>here i tried to create a copy of one of the arrayLists (selectedRow is just a number which says which arrayList i get)</p>

<pre><code>ArrayList&lt;Items&gt; newList = new ArrayList&lt;Items&gt;(arrayList.get(selectedRow));
</code></pre>

<p>After  i create another arrayList:</p>

<pre><code>   ArrayList&lt;Items&gt; changeList = new ArrayList&lt;Items&gt;(it.returnTheNewArrayList(newList,randomItem));
</code></pre>

<p>then in another class i create this method. The purpose of this method is to change an attribute of one of the objects.</p>

<pre><code>public  ArrayList&lt;Items&gt; returnTheNewArrayList(ArrayList&lt;Items&gt; a,int item){

  int randomBin = r.nextInt(50);

    for(Items i:a){

        if(item==i.itemIds()){

            while(randomBin==i.bins()){
                randomBin = r.nextInt(50);

            }
            i.setBin(randomBin);

        }

    }
return a;

}
</code></pre>

<p>Finally, i set the new arrayList in the 2d arrayList</p>

<pre><code> arrayList.set(whichList, changeList);
</code></pre>

<p>This is the procedure. i realize when i run this procedure that both newList and changeList are the same. In both of these arrayLists saved the change i did in the method returnTheNewArrayList(I realize this on the debuging). But i want to change only the one(the changeList). What i do wrong?</p>
