标签:java
| Vector():构造一个Vector对象,其内部数据数组大小为10及其标准容量增量为零。 | 
| Vector(Collection<?
 extends E> c):构造一个Vector对象,该对象的内容为Collection包含的所有元素,用于使用迭代器it
    erator访问其所有的元素 | 
| Vector(int initialCapacity):构造一个Vector对象,其内部数据数组大小为capacity及其标准容量增量为零。 | 
| Vector(int initialCapacity,
 int capacityIncrement):构造一个Vector对象,其内部数据数组大小为capacity及其标准容量增量为increment。 | 
| boolean | hasMoreElements():判定enumeration中是否还有元素 | 
| E | nextElement():返回enumeration对象中保存的一个元素(当前) | 
3.应用开发举例
<span style="font-family:Times New Roman;">import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
/*Vector集合类实现"动态数组"效果
 * 实现:从键盘输入一串数字序列并存储到一种数据结构中,从数据结构中取出数字并相加*/
public class TestVector {
 public static void main(String[] args)
 {
  int b=0;
  Vector v=new Vector();
  System.out.println("请输入数据:");
  while(true)
  {
  //1.从键盘读取一个字节
   try{
    b=System.in.read();
   }
   catch(IOException e)
   {
    System.out.println(e.getMessage());
   }
  //2.将字节转换为Integer对象,并存储到Vector结构体中
   if(b=='\r'||b=='\n')
   {
    break;	 //退出循环,即退出while
   }
   else
   {
    int num=b-'0';	 //由于键盘输入的为字符,1的ASCII码为。。。
    v.addElement(new Integer(num)); //将一个数字转换为整型对象,存储到vector数据结构中
   }
  }
 
  //3.使用Enumeration接口取出所有Vector集合类存储的对象
  int sum=0;
  Enumeration e=v.elements();	//a.从Vector取出所有对象元素
  while(e.hasMoreElements())	//b.判定是否到末尾,取出所有数字
  {
   Integer i=(Integer)e.nextElement();//获取一个数字元素对象,并将其转换为Integer包装类对象
   sum+=i.intValue();	 //读取Integer对象指定的数字
  }
  System.out.println(sum);//输出结果
 }
}</span>List list = Collections.synchronizedList(new ArrayList(...));
| ArrayList():构造一个空列表且容量为10的ArrayList对象Constructs an empty list with an initial capacity of ten. | 
| ArrayList(Collection<?
 extends E> c):Constructs
 a list containing the elements of the specified collection, in the order they are returned by the collection‘s iterator. | 
| ArrayList(int initialCapacity):Constructs
 an empty list with the specified initial capacity. | 
| boolean | hasNext()Returns  trueif the iteration has more elements. | 
| E | next()Returns the next element in the iteration. | 
| default void | remove()Removes from the underlying collection the last element returned by this iterator (optional operation). | 
<span style="font-family:Times New Roman;"><span style="font-size:18px;">import java.io.IOException;
import java.util.*;
/*ArrayList集合类实现"动态数组"效果
 * 实现:从键盘输入一串数字序列并存储到一种数据结构中,从数据结构中取出数字并相加*/
public class TestArrayList {
 public static void main(String[] args)
 {
  int b=0;
  ArrayList list=new ArrayList();
  System.out.println("请输入数据:");
  while(true)
  {
  //1.从键盘读取一个字节
   try{
    b=System.in.read();
   }
   catch(IOException e)
   {
    System.out.println(e.getMessage());
   }
  //2.将字节转换为Integer对象,并存储到Vector结构体中
   if(b=='\r'||b=='\n')
   {
    break;	 //退出循环,即退出while
   }
   else
   {
      int num=b-'0';	 //由于键盘输入的为字符,1的ASCII码为。。。
      list.add(new Integer(num)); //将一个数字转换为整型对象,存储到vector数据结构中
   }
  }
 
  //3.使用Enumeration接口取出所有Vector集合类存储的对象
  int sum=0;
  Iterator i=list.iterator();	//a.从Vector取出所有对象元素
  while(i.hasnext())	//b.判定是否到末尾,取出所有数字
  {
   Integer intObj=(Integer)e.next();//获取一个数字元素对象,并将其转换为Integer包装类对象
   sum+=intObj.intValue();	 //读取Integer对象指定的数字
  }
  System.out.println(sum);//输出结果
 }
}</span></span><span style="font-family:Times New Roman;"><span style="font-size:18px;">import java.util.*;
public class  TestSort
{
    public static void main(String[] args)
    {
        ArrayList list=new ArrayList();
        list.add(new Integer(1));
        list.add(new Integer(3));
        list.add(new Integer(2));
        System.out.println(list.toString());    //排序前
        Collections.sort(list);
        System.out.println(list.toString());    //排序后
    }
}</span></span>标签:java
原文地址:http://blog.csdn.net/u012637501/article/details/43153057