Two options come to mind:
- Call the
ArrayList constructor which takes another collection - that'll make a copy
- Call
clone() on the ArrayList
Note that both of these will create shallow copies - each list will contain references to the same objects. That's fine if they're immutable (like strings) but if you want to create a deeper copy you'll need to do more work.
Is there any reason you're not using generics, by the way? For example, I would probably use:
LinkedList<ArrayList<String>> partials = new LinkedList<ArrayList<String>>();
ArrayList<String> list = new ArrayList<String>();
list.add("Test");
// Create a shallow copy and add a reference to that into the linked list
partials.add(new ArrayList<String>(list));
list.add("Another element");
// Prints 1, because the lists are distinct
System.out.println(partials.element().size());
If nothing should ever change the contents of the lists in the linked list, you may want to look at the immutable collections available in Guava, or wrap your clone using Collections.unmodifiableList. Note that the latter only creates a view on the original list, so you'd still need to perform the clone step first.