java - Removing even elements from a list -
this question has answer here:
- remove numbers arraylist 7 answers
how can remove elements list of integers?
list dropeven(list l, int n) { list to_return = nil(); while(true) { if(l.isempty()) return to_return; if(n==0) l.remove(n); integer = (integer)(hd(l)); to_return=append1(to_return,hd(l)); n= n-1; l=tl(l); } }
user iterator , remove values
iterator = l.iterator; int counter = 0; while(i.hasnext()){ i.next(); if (counter%2 == 0) i.remove(); counter++; }
Comments
Post a Comment