class A{
String tt="sss";
}
@Test
public void test4() throws FileNotFoundException {
try {
ArrayList<A> a = new ArrayList<A>();
a.add(new A());
a.add(new A());
ArrayList<A> b = new ArrayList<A>();
b.add(new A());
b.add(new A());
a.addAll(b);
b.get(0).tt="dd";
System.out.println("b.size:"+b.size());
for(A ssa:a){
System.out.println("a list:"+ssa.tt);
}
} catch (Exception e) {
e.printStackTrace();
}
}
输出的结果为:
b.size:2
a list:sss
a list:sss
a list:dd
a list:sss
说明addAll方法只是拷贝了对象的地址,并没有完全复制一份对象