The statement j=i;
assigns the reference j
to be the same reference as i
. Now both i
and j
refer to the same ArrayList
object. The removal of the 0th index is simply visible through both references.
If you would like the removal of an item in i
not to affect the list from j
, then create a copy of the list, instead of assigning the references:
j = new ArrayList<Integer>(i);
(It's a shallow copy, so the lists still refer to the same elements.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…