日期:2014-05-20 浏览次数:20818 次
import java.util.Enumeration;
import java.util.Vector;
public class Test {
private int i = 0;
private boolean isBusy;
public Test(int i, boolean isBusy) {
this.i = i;
this.isBusy = isBusy;
}
public static void main(String[] args) {
Vector vector = new Vector();
for (int i = 0; i < 10; i++) {
vector.addElement(new Test(i, false));
System.out.println("add");
}
Enumeration en = vector.elements();
while (en.hasMoreElements()) {
Test tt = (Test)en.nextElement();
vector.remove(tt);
System.out.println("remove");
// en = vector.elements();
}
}
}
public Enumeration<E> elements() {
return new Enumeration<E>() {
int count = 0;
public boolean hasMoreElements() {
return count < elementCount;
}
public E nextElement() {
synchronized (Vector.this) {
if (count < elementCount) {
return elementData(count++);
}
}
throw new NoSuchElementException("Vector Enumeration");
}
};
}