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 

  • 相关阅读:
    90后是怎么了
    从GNOME切换到KDE了
    Ubuntu 12.04中安装Evolus Pencil原型图绘制软件
    wine qq 2012 for linux
    发现来博客园比去csdn早
    [转]代理(Proxy)和委派(Delegate)的区别
    Debian Stable分支对于开发者的意义[续软件系统。。。]
    xj3d svn org.web3d目录结构分析
    不自觉的就陷入OS发行版选择的泥潭
    DNN Test
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11704767.html
Copyright © 2011-2022 走看看