vectordemo.java~1~

来自「java2参考大全上的例子的源码和自己的理解.」· JAVA~1~ 代码 · 共 66 行

JAVA~1~
66
字号
package vector;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

// Demonstrate various Vector operations.
import java.util.*;

class VectorDemo {
  public static void main(String args[]) {

    // initial size is 3, increment is 2
    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();
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?