Java中Vector的使用方法

Vector创建,添加元素,删除元素,获得元素数量。

 1 import java.util.*;
 2 pulic class VectorDemo{
 3     public static void main(String[] args){
 4         //creat vector 
 5         Vector v = new Vector(1);
 6         //add element at the end of Vector
 7         v.add("Test0");
 8         v.add("Test1");
 9         //delete element by content or location
10         v.remove("Test1");
11         v.remove(0);
12         //get element amount
13         int size = v.size();
14         }
15 }

Vector有三个构造函数:

//定义初始容量和自定义的增量,即增加容量时增加的大小
public Vector(int initialCapacity, int capacityIncrement);
//定义初始容量
public Vector(int intialCapacity);
//不定义初始容量
public Vector();

 

 

私货:

诶果然还是博客园这种内嵌代码模式适合写笔记。笔记类应用不靠谱啊不靠谱。

首先ArrayList 比 Vector快,但是是非同步的,如果涉及多线程,还是使用Vector。

posted @ 2014-04-22 16:14  黄天河·Solare  阅读(361)  评论(0编辑  收藏  举报