Java 数据结构 --> Vector 类
来源:互联网 发布:电脑维修书籍推荐 知乎 编辑:程序博客网 时间:2024/06/05 05:36
Vector是同步访问的。
Vector包含了许多传统的方法,这些方法不属于集合框架。
Vector主要用在事先不知道数组的大小,或者只是需要一个可以改变大小的数组的情况。
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());
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 vEnum = v.elements();
System.out.println("\nElements in vector:");
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:
1 2 3 4 5.45 6.08 7 9.4 10 11 12
- Java 数据结构 --> Vector 类
- java数据结构之向量Vector
- Java数据结构 ArrayList、LinkList、Vector
- Java数据结构源码分析-Vector
- Java数据结构--跟着api学数据结构--Vector
- Java数据结构——Stack和父类Vector
- Java数据结构-Vector(五)
- Java 数据结构之 Vector(mark)
- 数据结构-vector
- Java数据结构 老版本的数据结构Vector、Stack
- 关于java Vector类
- 《java中的vector类》
- java中的Vector类
- java中的Vector类
- java中的Vector类
- java中的Vector类
- Java:类Vector
- java中的Vector类
- 802.11协议精读18:协议族框架简介
- romfs-inst.sh $(ROMFSINST)
- 二维码生成和解析代码
- jq相关:触摸事件 ontouchstart、ontouchmove、ontouchend、ontouchcancel的区别
- 推荐一本书《人体使用手册》
- Java 数据结构 --> Vector 类
- 使用canvas fingerprinting追踪用户信息
- 从AlexNet到squeezenet
- jq 查找控件
- linux面试题
- PowerDesigner导入sql文件
- python 乘法口诀
- MFC使用windows图片查看器
- MySQL中函数CONCAT&CONCAT_WS及GROUP_CONCAT