提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用Iterator遍历元素Vector
import java.util.Vector; /** 来 自 n o w j a v a . c o m **/ import java.util.Iterator; public class Main { public static void main(String[] args) { Vector v = new Vector(); v.add("1"); v.add("2"); v.add("3"); v.add("4"); v.add("5"); //get an Iterator object for Vector using iterator() method. Iterator itr = v.iterator(); //use hasNext() and next() methods of Iterator to iterate through the elements//n o w j a v a . c o m 提供 while(itr.hasNext()) System.out.println(itr.next()); } }