zoukankan      html  css  js  c++  java
  • java 动态数组

    package testjavapro;
    import java.util.*;
    
    public class testjava {
    
       public static void main(String args[]) {
          // initial size is 3, Capacity increment is 2
          Vector<Number> v = new Vector<Number>(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<Number> vEnum = v.elements();
          System.out.println("
    Elements in vector:"+v.size());
          while(vEnum.hasMoreElements())
             System.out.print(vEnum.nextElement() + " ");
          System.out.println();
       }
    }

    输出

    Initial size: 0
    Initial capacity: 3
    Capacity after four additions: 5
    Current capacity: 5
    Current capacity: 7
    Current capacity: 9
    First element: 1
    Last element: 12
    Vector contains 3.
    
    Elements in vector:11
    1 2 3 4 5.45 6.08 7 9.4 10 11 12 

  • 相关阅读:
    HDU 5213 分块 容斥
    HDU 2298 三分
    HDU 5144 三分
    HDU 5145 分块 莫队
    HDU 3938 并查集
    HDU 3926 并查集 图同构简单判断 STL
    POJ 2431 优先队列
    HDU 1811 拓扑排序 并查集
    HDU 2685 GCD推导
    HDU 4496 并查集 逆向思维
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11704767.html
Copyright © 2011-2022 走看看