I have code as follows:
//Assume a has one arrayList in it
List<List<Integer>> a1 = new ArrayList<List<Integer>>(a);
for(int i=0;i<1;i++){
List<Integer> b1 = a1.get(i);
b1.add(0);
}
System.out.println(a.toString()); //now there are 2 elements in arraylist a
I thought the above code make change only on a1
. But the print out result shows that both arraylist a1
and a
are changed. How can I make only a1
change without a
changed as well.
>`, then the element adding of `a1` will not change the element of `a`. Why is it