向量(Vector)
向量(Vector)類和傳統數組非常相似,但是Vector的大小能根據需要動態的變化。
和數組一樣,Vector對象的元素也能通過索引訪問。 和 ArrayList 很相似,但Vector 是同步訪問的。
使用Vector類最主要的好處就是在創建對象的時候不必給對象指定大小,它的大小會根據需要動態的變化。
Vector();Vector(int size);Vector(int size,int incr);Vector(Collection c);
序號
? ??
方法描述
1
? ??
void add(int index, Object element)?
?在此向量的指定位置插入指定的元素。
2
? ??
boolean add(Object o)?
?將指定元素添加到此向量的末尾。
3
? ??
boolean addAll(Collection c)?
將指定 Collection 中的所有元素添加到此向量的末尾,按照指定 collection 的迭代器所返回的順序添加這些元素。
4
? ??
boolean addAll(int index, Collection c)?
在指定位置將指定 Collection 中的所有元素插入到此向量中。
5
? ??
void addElement(Object obj)?
?將指定的組件添加到此向量的末尾,將其大小增加 1。
6
? ??
int capacity()?
返回此向量的當前容量。
7
? ??
void clear()?
從此向量中移除所有元素。
8
? ??
Object clone()?
返回向量的一個副本。
9
? ??
boolean contains(Object elem)?
如果此向量包含指定的元素,則返回 true。
10
? ??
boolean containsAll(Collection c)?
如果此向量包含指定 Collection 中的所有元素,則返回 true。
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()?
返回此向量的第一個組件(位于索引 0) 處的項)。
17
? ??
Object get(int index)?
返回向量中指定位置的元素。
18
? ??
int hashCode()?
返回此向量的哈希碼值。
19
? ??
int indexOf(Object elem)?
?返回此向量中第一次出現的指定元素的索引,如果此向量不包含該元素,則返回 -1。
20
? ??
int indexOf(Object elem, int index)?
?返回此向量中第一次出現的指定元素的索引,從 index 處正向搜索,如果未找到該元素,則返回 -1。
21
? ??
void insertElementAt(Object obj, int index)?
將指定對象作為此向量中的組件插入到指定的 index 處。
22
? ??
boolean isEmpty()?
測試此向量是否不包含組件。
23
? ??
Object lastElement()?
返回此向量的最后一個組件。
24
? ??
int lastIndexOf(Object elem)?
?返回此向量中最后一次出現的指定元素的索引;如果此向量不包含該元素,則返回 -1。
25
? ??
int lastIndexOf(Object elem, int index)?
返回此向量中最后一次出現的指定元素的索引,從 index 處逆向搜索,如果未找到該元素,則返回 -1。
26
? ??
Object remove(int index)?
?移除此向量中指定位置的元素。
27
? ??
boolean remove(Object o)?
移除此向量中指定元素的第一個匹配項,如果向量不包含該元素,則元素保持不變。
28
? ??
boolean removeAll(Collection c)?
從此向量中移除包含在指定 Collection 中的所有元素。
29
? ??
void removeAllElements()?
從此向量中移除全部組件,并將其大小設置為零。
30
? ??
boolean removeElement(Object obj)?
從此向量中移除變量的第一個(索引最小的)匹配項。
31
? ??
void removeElementAt(int index)?
刪除指定索引處的組件。
32
? ??
protected void removeRange(int fromIndex, int toIndex)
從此 List 中移除其索引位于 fromIndex(包括)與 toIndex(不包括)之間的所有元素。
33
? ??
boolean retainAll(Collection c)?
在此向量中僅保留包含在指定 Collection 中的元素。
34
? ??
Object set(int index, Object element)
?用指定的元素替換此向量中指定位置處的元素。
35
? ??
void setElementAt(Object obj, int index)?
將此向量指定 index 處的組件設置為指定的對象。
36
? ??
void setSize(int newSize)?
?設置此向量的大小。
37
? ??
int size()?
?返回此向量中的組件數。
38
? ??
List subList(int fromIndex, int toIndex)?
返回此 List 的部分視圖,元素范圍為從 fromIndex(包括)到 toIndex(不包括)。
39
? ??
Object[] toArray()
?返回一個數組,包含此向量中以恰當順序存放的所有元素。
40
? ??
Object[] toArray(Object[] a)?
返回一個數組,包含此向量中以恰當順序存放的所有元素;返回數組的運行時類型為指定數組的類型。
41
? ??
String toString()?
返回此向量的字符串表示形式,其中包含每個元素的 String 表示形式。
42
? ??
void trimToSize()?
? 對此向量的容量進行微調,使其等于向量的當前大小。
?