【发布时间】:2015-01-11 15:58:07
【问题描述】:
public static void main(String[] args) {
List<List<Integer>> ll1 = new ArrayList<List<Integer>>();
ll1.add(new ArrayList<Integer>(1));
System.out.println(ll1.get(0));
//hard copy don't work
List<List<Integer>> ll2 = new ArrayList<List<Integer>>(ll1);
System.out.println(ll2.get(0) == ll1.get(0));
}
除了使用 for 循环对每个内部列表进行硬拷贝之外,我们是否还有另一种方式来进行硬拷贝。
您能解释一下List<List<Integer>> ll2 = new ArrayList<List<Integer>>(ll1); 的工作原理以及失败的原因吗?
【问题讨论】: