Vector
Vector 类实现了一个动态数组。和 ArrayList 很相似,但是两者是不同的:
Vector 是同步访问的。
Vector 包含了许多传统的方法,这些方法不属于集合框架。
Vector 主要用在事先不知道数组的大小,或者只是需要一个可以改变大小的数组的情况。
Vector 类支持 4 种构造方法。
第一种构造方法创建一个默认的向量,默认大小为 10:
Vector()
第二种构造方法创建指定大小的向量。
Vector(int size)
第三种构造方法创建指定大小的向量,并且增量用 incr 指定。增量表示向量每次增加的元素数目。
Vector(int size,int incr)
第四种构造方法创建一个包含集合 c 元素的向量:
Vector(Collection c)
除了从父类继承的方法外 Vector 还定义了以下方法:
|
序号 |
方法描述 |
|
1 |
void add(int index, Object element) |
|
2 |
boolean add(Object o) |
|
3 |
boolean addAll(Collection c) |
|
4 |
boolean addAll(int index, Collection c) |
|
5 |
void addElement(Object obj) |
|
6 |
int capacity() |
|
7 |
void clear() |
|
8 |
Object clone() |
|
9 |
boolean contains(Object elem) |
|
10 |
boolean containsAll(Collection c) |
|
11 |
void copyInto(Object[] anArray) |
|
12 |
Object elementAt(int index) |
|
13 |
Enumeration elements() |
|
14 |
void ensureCapacity(int minCapacity) |
|
15 |
boolean equals(Object o) |
|
16 |
Object firstElement() |
|
17 |
Object get(int index) |
|
18 |
int hashCode() |
|
19 |
int indexOf(Object elem) |
|
20 |
int indexOf(Object elem, int index) |
|
21 |
void insertElementAt(Object obj, int index) |
|
22 |
boolean isEmpty() |
|
23 |
Object lastElement() |
|
24 |
int lastIndexOf(Object elem) |
|
25 |
int lastIndexOf(Object elem, int index) |
|
26 |
Object remove(int index) |
|
27 |
boolean remove(Object o) |
|
28 |
boolean removeAll(Collection c) |
|
29 |
void removeAllElements() |
|
30 |
boolean removeElement(Object obj) |
|
31 |
void removeElementAt(int index) |
|
32 |
protected void removeRange(int fromIndex, int toIndex) |
|
33 |
boolean retainAll(Collection c) |
|
34 |
Object set(int index, Object element) |
|
35 |
void setElementAt(Object obj, int index) |
|
36 |
void setSize(int newSize) |
|
37 |
int size() |
|
38 |
List subList(int fromIndex, int toIndex) |
|
39 |
Object[] toArray() |
|
40 |
Object[] toArray(Object[] a) |
|
41 |
String toString() |
|
42 |
void trimToSize() |

浙公网安备 33010602011771号