⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vectortest.java

📁 用户需要使用某个文件时
💻 JAVA
字号:
/*源程序清单6-3*/

package test;

import java.util.*;
import java.awt.*;

public class VectorTest
{
  Vector sam=new Vector(15,3);

  public VectorTest()
  {
    System.out.println("The vector's init capacity is:"+sam.capacity());
    System.out.println("The vector's init size is:"+sam.size());
    System.out.println("Insert 0-9 to Vector");
    for(int i=0;i<10;i++)
      sam.addElement(new Integer(i));
    System.out.println("The vector's capacity is:"+sam.capacity());
    System.out.println("The vector's size is:"+sam.size());
    System.out.println("Insert button0-button9 to Vector");
    for(int i=0;i<10;i++)
    {
      Button button=new Button("button"+Integer.toString(i));
      sam.addElement(button);
    }
    System.out.println("The vector's capacity is:"+sam.capacity());
    System.out.println("The vector's size is:"+sam.size());
    int index=sam.indexOf(new Integer(6));
    System.out.println("The index of 6 in the vector is:"+index);
    int firstNumber=((Integer)sam.firstElement()).intValue();
    System.out.println("The first element in the vector is:"+firstNumber);
    Button button=(Button)sam.lastElement();
    System.out.println("The last element in the vetor is:"+button.getLabel());
    System.out.println("Remove 4 element in the vector");
    for(int i=8;i<12;i++)
      sam.removeElementAt(i);
    System.out.println("The vector's capacity is:"+sam.capacity());
    System.out.println("The vector's size is:"+sam.size());
    System.out.println("Trim the vector to size");
    sam.trimToSize();
    System.out.println("The vector's capacity is:"+sam.capacity());
    System.out.println("The vector's size is:"+sam.size());
    System.out.println("Remove all element of the vector");
    sam.removeAllElements();
    System.out.println("The vector's capacity is:"+sam.capacity());
    System.out.println("The vector's size is:"+sam.size());
    sam.trimToSize();
    System.out.println("Trim the vector to size");
    System.out.println("The vector's last capacity is:"+sam.capacity());
    System.out.println("The vector's last size is:"+sam.size());
  }

  public static void main(String[] args)
  {
    try
    {
      new VectorTest();
      System.in.read();
    }
    catch(Exception e)
    {
      System.out.println(e.toString());
    }
  }
}

⌨️ 快捷键说明

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