import java.util.Iterator;
import java.util.Vector;
public class VectorIterator implements Iterator{
private Vector v;
private int currentIndex=0;
public VectorIterator(){
}
public VectorIterator(Vector v){
this.v=v;
}
public boolean hasNext() {
if(this.currentIndex<this.v.size()){
System.out.println("current index is : "+this.currentIndex);
return true;
}else{
System.out.println("out of the bound ");
}
return false;
}
public Object next() {
return this.v.get(this.currentIndex++);
}
public void remove() {
this.v.remove(this.currentIndex);
}
public static void main(String[] args){
Vector v=new Vector();
v.add(new String("aaa"));
v.add(new String("bbb"));
v.add(new String("ccc"));
//System.out.println(v);
Iterator iter=new VectorIterator(v);
while(iter.hasNext()){
String str=(String)iter.next();
System.out.println(str);
}
}
}
posted on 2010-01-26 09:08
luis 阅读(1096)
评论(0) 编辑 收藏 引用 所属分类:
转载 、
Java笔记