Vector Enumeration 示例

876人阅读 评论(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());

System.out.println("Capacity after four additions:" + v.capacity());

System.out.println("Current capacity :" + v.capacity());

System.out.println("Current capacity :" + v.capacity());

System.out.println("Current capacity :" + v.capacity());

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 enum = v.elements();

System.out.println("Elements in vector:");
while(enum.hasMoreElements()){
System.out.print(enum.nextElement() + " ");
}
System.out.println();

/*
//use an iterator to display contents
Iterator i = v.iterator();

System.out.println("Elements in vector:");
while(i.hasNext()){
System.out.print(i.next() + " ");
}
System.out.println();
*/
}
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：680786次
• 积分：7852
• 等级：
• 排名：第2626名
• 原创：75篇
• 转载：247篇
• 译文：0篇
• 评论：64条
文章分类
评论排行
最新评论
Flex+Java And Flash+Php