arraylist copy to another arraylist code example

Example: copy arraylist to another arraylist java

You can use such trick:

myObject = new ArrayList<Object>(myTempObject);
or use

myObject = (ArrayList<Object>)myTempObject.clone();
You can get some information about clone() method here

But you should remember, that all these ways will give you a copy of your List, not all of its elements. So if you change one of the elements in your copied List, it will also be changed in your original List.

Tags:

Java Example