Java Vector 类

import java.util.*;

public class VectorDemo {

public static void main(String[] args) {
    
    Vector v = new Vector(3, 2);
    System.out.println("Initial size: " + v.size());
    System.out.println("Initial capacity: " + v.capacity());
    
    v.addElement(new Integer(1));
    v.addElement(new Integer(2));
    v.addElement(new Integer(3));
    v.addElement(new Integer(4));
    System.out.println("Capacity after four additions: " + v.capacity());
    
    v.addElement(new Double(5.45));
    System.out.println("Current capacity: " + v.capacity());
    
    v.addElement(new Double(6.08));
    v.addElement(new Integer(7));
    System.out.println("Current capacity: " + v.capacity());
    
    v.addElement(new Float(9.4));
    v.addElement(new Integer(10));
    System.out.println("Current capacity: " + v.capacity());
    
    v.addElement(new Integer(11));
    v.addElement(new Integer(12));
    System.out.println("First element: " + (Integer)v.firstElement());
    System.out.println("Last element: " + (Integer)v.lastElement());
    
    if(v.contains(new Integer(3)))
    System.out.println("Vector contains 3.");
    
    // enumerate the elements in the vector.
    Enumeration vEnum = v.elements();
    System.out.println("\nElements in vector:");
    
    while(vEnum.hasMoreElements())
    System.out.print(vEnum.nextElement() + " ");
    System.out.println();
    
}

}

推荐阅读更多精彩内容

  • 【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔...
    Bamboo1688阅读 675评论 0 8
  • 多态 任何域的访问操作都将有编译器解析,如果某个方法是静态的,它的行为就不具有多态性 java默认对象的销毁顺序与...
    yueyue_projects阅读 252评论 0 1
  • Java经典问题算法大全 /*【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子...
    江湖宇阅读 530评论 0 0
  • 小编费力收集:给你想要的面试集合 1.C++或Java中的异常处理机制的简单原理和应用。 当JAVA程序违反了JA...
    江湖里的一把剑阅读 2,681评论 1 115
  • 本文包括:1、Listener简介2、Servlet监听器3、监听三个域对象创建和销毁的事件监听器4、监听三个域对...
    廖少少阅读 1,421评论 6 25