Getting only last element of arraylist and losing old elements
<p>I have a problem about Arraylists. I created an arraylist of user defined object. In my drawing program, I created a class which takes only this arraylist. In another class I create this object, and I create another arraylist which takes these objects. You can understand better if you can look up my code. The problem is I have to remove all elements of the object's arraylist after adding to the last arraylist. But I always lose elements after removing. I used clone() method then I keep always last elements. I know its coplicated here, sorry about my english, you can understand clearly what I mean if you can check my code.</p>

<pre><code> public class Lines {

public int id;
public Point point1;
public Point point2;
public int[] denklem;
}

public class Devline {
ArrayList&lt;Lines&gt; segmentim = new ArrayList&lt;Lines&gt;();

 }
...
Devline devarray = new Devline();
Devline devarray3 = new Devline();
ArrayList&lt;Devline&gt; devarray2 = new ArrayList&lt;Devline&gt;();

if(SwingUtilities.isRightMouseButton(e) == true){
        devarray3.segmentim =  (ArrayList&lt;Lines&gt;) devarray.segmentim.clone();
        devarray2.add(devarray3);
        devarray = new Devline();
        begin = true;

    }
</code></pre>

<p>Here how I add an element to devarray.</p>

<pre><code>  devarray.segmentim.add(l1);
</code></pre>

<p>I need to add all elements to my devarray2 list. Each time I click rightbutton it will add devarray elements into devarray2, so I can make many different devarray elements inside devarray2. Thank you.</p>
