|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Vector
Vector class (a growable array).
Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement. The capacity is always at least as large as the vector size; it is usually larger because as elements are added to the vector, the vector's storage increases in chunks the size of capacityIncrement. Setting the capacity to what you want before inserting a large number of objects will reduce the amount of incremental reallocation. You can safely ignore the capacity and the vector will still work correctly.
Field Summary | |
protected int |
capacityIncrement
The size of the increment. |
protected int |
elementCount
The number of elements in the buffer. |
protected Object[] |
elementData
The buffer where elements are stored. |
Constructor Summary | |
Vector()
Constructs an empty vector. |
|
Vector(int initialCapacity)
Constructs an empty vector with the specified storage capacity. |
|
Vector(int initialCapacity,
int capacityIncrement)
Constructs an empty vector with the specified storage capacity and the specified capacityIncrement. |
Method Summary | |
void |
addElement(Object obj)
Adds the specified object as the last element of the vector. |
int |
capacity()
Returns the current capacity of the vector. |
Object |
clone()
Clones this vector. |
boolean |
contains(Object elem)
Returns true if the specified object is a value of the collection. |
void |
copyInto(Object[] anArray)
Copies the elements of this vector into the specified array. |
Object |
elementAt(int index)
Returns the element at the specified index. |
Enumeration |
elements()
Returns an enumeration of the elements. |
void |
ensureCapacity(int minCapacity)
Ensures that the vector has at least the specified capacity. |
Object |
firstElement()
Returns the first element of the sequence. |
int |
indexOf(Object elem)
Searches for the specified object, starting from the first position and returns an index to it. |
int |
indexOf(Object elem,
int index)
Searches for the specified object, starting at the specified position and returns an index to it. |
void |
insertElementAt(Object obj,
int index)
Inserts the specified object as an element at the specified index. |
boolean |
isEmpty()
Returns true if the collection contains no values. |
Object |
lastElement()
Returns the last element of the sequence. |
int |
lastIndexOf(Object elem)
Searches backwards for the specified object, starting from the last position and returns an index to it. |
int |
lastIndexOf(Object elem,
int index)
Searches backwards for the specified object, starting from the specified position and returns an index to it. |
void |
removeAllElements()
Removes all elements of the vector. |
boolean |
removeElement(Object obj)
Removes the element from the vector. |
void |
removeElementAt(int index)
Deletes the element at the specified index. |
void |
setElementAt(Object obj,
int index)
Sets the element at the specified index to be the specified object. |
void |
setSize(int newSize)
Sets the size of the vector. |
int |
size()
Returns the number of elements in the vector. |
String |
toString()
Converts the vector to a string. |
void |
trimToSize()
Trims the vector's capacity down to size. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Object[] elementData
protected int elementCount
protected int capacityIncrement
Constructor Detail |
public Vector(int initialCapacity, int capacityIncrement)
initialCapacity
- the initial storage capacity of the vectorcapacityIncrement
- how much to increase the element's
size by.public Vector(int initialCapacity)
initialCapacity
- the initial storage capacity of the vectorpublic Vector()
Method Detail |
public final void copyInto(Object[] anArray)
anArray
- the array where elements get copied intopublic final void trimToSize()
public final void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacitypublic final void setSize(int newSize)
newSize
- the new size of the vectorpublic final int capacity()
public final int size()
public final boolean isEmpty()
public final Enumeration elements()
public final boolean contains(Object elem)
elem
- the desired elementpublic final int indexOf(Object elem)
elem
- the desired element
public final int indexOf(Object elem, int index)
elem
- the desired elementindex
- the index where to start searching
public final int lastIndexOf(Object elem)
elem
- the desired element
public final int lastIndexOf(Object elem, int index)
elem
- the desired elementindex
- the index where to start searching
public final Object elementAt(int index)
index
- the index of the desired element
ArrayIndexOutOfBoundsException
- If an invalid
index was given.public final Object firstElement()
NoSuchElementException
- If the sequence is empty.public final Object lastElement()
NoSuchElementException
- If the sequence is empty.public final void setElementAt(Object obj, int index)
obj
- what the element is to be set toindex
- the specified index
ArrayIndexOutOfBoundsException
- If the index was
invalid.public final void removeElementAt(int index)
index
- the element to remove
ArrayIndexOutOfBoundsException
- If the index was invalid.public final void insertElementAt(Object obj, int index)
obj
- the element to insertindex
- where to insert the new element
ArrayIndexOutOfBoundsException
- If the index was invalid.public final void addElement(Object obj)
obj
- the element to be addedpublic final boolean removeElement(Object obj)
obj
- the element to be removed
public final void removeAllElements()
public Object clone()
clone
in class Object
public final String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |