如何将一个列表复制到另一个列表,并对新列表中包含的对象进行更改,而不影响旧列表中的对象?
class Foo {
String title;
void setTitle(String title) { this.title = title; }
}
List<Foo> original;
List<Foo> newlist = new ArrayList<Foo>(original);
for (Foo foo : newlist) {
foo.setTitle("test"); //this will also affect the objects in original list.
//how can I avoid this?
}