【发布时间】:2010-11-22 18:01:17
【问题描述】:
我有一个如下示例程序:
ArrayList<Invoice> orginalInvoice = new ArrayList<Invoice>();
//add some items into it here
ArrayList<Invoice> copiedInvoice = new ArrayList<Invoice>();
copiedInvoice.addAll(orginalInvoice);
我想我可以修改copiedInvoice 中的项目,它不会影响originalInoice 中的这些项目。但是我错了。
如何制作ArrayList 的单独副本/克隆?
谢谢
【问题讨论】:
-
可能重复:stackoverflow.com/questions/715650/… 正如 Zed 提到的那样。
-
我将其作为副本关闭,但不应将其删除。不是每个人都会知道使用原始使用的技术上更正确的“克隆”术语进行搜索。