import java.util.*;
class Test {
public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<Integer>();
ArrayList<Integer> b = new ArrayList<Integer>();
//added 0-9 to ArrayList
for(int i=0;i<9;i++)
a.add(new Integer(i));
//initialize the Iterator
ListIterator<Integer> i = a.listIterator();
while(i.hasNext())
System.out.print(i.next());
System.out.print(" ");
b = a;
Collections.shuffle(a);
//initialized the iterator again and print all the elements
i = b.listIterator();
while(i.hasNext())
System.out.print(i.next());
}
}
//Output : 012345678 528430617
根据上面的代码,如果我正在改组 ArrayList a 那么 ArrayList b 也会更新所以即使在更新之后我怎么能看到它不应该更新 b