Best way to transfer value from an ArrayList to another
java
Solution
The first one replaces the content of the list by another content. The second one creates another ArrayList instance, leaving the previous one untouched.
If the list is referenced by some other object, and you want this other object to be untouched, use the second one. If you want the other object to also have the new content, use the first one.
If nothing else referenced the list, it doesn't matter much. The second one will reduce the memory used in case you replace the content of a huge list by a few elements.
Problem
With 2 ArrayList, I was wondering if the best way from transforming the 1st one into a "copy" of the second one is to go like ``` myFirstArray.clear(); myFirstArray.addAll(mySecondArray); ``` or ``` myFirstArray = mySecondArray.clone(); ``` What are the main differences between those two method, which on is preferrable and is there another "easier" or "cleaner" solution. Thanks for any tips EDIT : I use this copy for replacing an Array of item im currently working with the one where I store the item I'll work with in the next loop. At the end of the loop I replace my currentArrayList with my futurArrayList and I clear my futurArraylist in order to add new item in it (i hope its clear enough)