Java create subList and remove values from previous List -
i want create sublist in java , remove values in sublist previous list. program correctly creates sublist, doesn't remove correct values previouslist.
my code:
for(int i=0; i<4; i++){ list<object> sub=new arraylist<object>(prevoiuslist.sublist(0,6)); (int j=0; j<6; j++){ previouslist.remove(j); } }
at first j=0
, remove first element. when doing shift other elements, second element becomes first , on.
on next iteration j=1
, remove second element, third...
in order fix issue, use 0
index, or iterator.
Comments
Post a Comment