posts - 195,  comments - 30,  trackbacks - 0
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 阅读(1090) 评论(0)  编辑 收藏 引用 所属分类: 转载Java笔记

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年1月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

友情链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜