I have quite large List named items (>= 1,000,000 items) and some condition denoted by
Rather than muddying my first answer, which is already rather long, here's a second, related option: you can create your own ArrayList, and flag things as "removed". This algoritm makes the assumptions:
Also, this is, again, not tested so there's prlolly syntax errors.
public class FlaggedList extends ArrayList {
private Vector flags = new ArrayList();
private static final String IN = Boolean.TRUE; // not removed
private static final String OUT = Boolean.FALSE; // removed
private int removed = 0;
public MyArrayList(){ this(1000000); }
public MyArrayList(int estimate){
super(estimate);
flags = new ArrayList(estimate);
}
public void remove(int idx){
flags.set(idx, OUT);
removed++;
}
public boolean isRemoved(int idx){ return flags.get(idx); }
}
and the iterator - more work may be needed to keep it synchronized, and many methods are left out, this time:
public class FlaggedListIterator implements ListIterator
{
int idx = 0;
public FlaggedList list;
public FlaggedListIterator(FlaggedList list)
{
this.list = list;
}
public boolean hasNext() {
while(idx