See the following code:
int indices[100] ; // indices array contains list of indices of elements to be removed from list
indices[0]=3;
indices[1]=6;
indices[2]=12;
for(int i=0;i
}
Now if u feel that above code is fyn...u r in a soup ;-) Try executing it ...U will get ArrayIndexOutofBoundsException...
Wonder yyyy??????Its silly actually.
The key is when u remove an element from a list...the remaining elements will push each one a level forward.. say u removed an element with index 5 , now 6 element will become 5.. and 7 th element will become 6 element ..
So while removing items in a loop the logic should be chosen accordingly...
1 comment:
sorry..I had some minor mistakes in the sample code above earlier and i fixed it now...gud thing is no one pointed out;-)
Post a Comment