1 import java.util.Vector; 2 3 public class VectorDemo { 4 static String[] months = {"Janunary","February","March","aprile","May","June","July","Aug","Sep", 5 "October","November"}; 6 public static void main(String[] args) { 7 8 Vector vq =new Vector(); 9 10 for(int i=0;i<months.length;i++){ 11 vq.addElement(months[i] + " "); //进队列对象放入尾部 12 } 13 14 if(vq.isEmpty()){ 15 System.out.println("kong"); 16 } 17 18 while(!vq.isEmpty()){ //出队列从头部取 19 System.out.println(vq.firstElement()); 20 vq.removeElement(vq.firstElement()); 21 } 22 23 vq.clear(); 24 } 25 }
输出结果为:
Janunary
February
March
aprile
May
June
July
Aug
Sep
October
November