How do I copy the contents of one ArrayList into another?
问题 I have some data structures, and I would like to use one as a temporary, and another as not temporary. ArrayList<Object> myObject = new ArrayList<Object>(); ArrayList<Object> myTempObject = new ArrayList<Object>(); //fill myTempObject here .... //make myObject contain the same values as myTempObject myObject = myTempObject; //free up memory by clearing myTempObject myTempObject.clear(); now the problem with this of course is that myObject is really just pointing to myTempObject , and so once