java.lang.Object | |||
↳ | java.util.AbstractCollection<E> | ||
↳ | java.util.AbstractList<E> | ||
↳ | java.util.Vector<E> |
![]()
Stack<T>
|
The Vector
class implements a growable array of objects. Like an
array, it contains components that can be accessed using an integer index.
However, the size of a Vector
can grow or shrink as needed to
accommodate adding and removing items after the Vector
has been
created.
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 components are added to the vector, the vector's
storage increases in chunks the size of capacityIncrement
. An
application can increase the capacity of a vector before inserting a large
number of components; this reduces the amount of incremental reallocation.
Note: To conserve space, the CLDC implementation is based on JDK 1.1.8, not JDK 1.3.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
protected int | capacityIncrement | The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. | |||||||||
protected int | elementCount | The number of valid components in the vector. | |||||||||
protected E[] | elementData | The array buffer into which the components of the vector are stored. |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Vector(int initialCapacity, int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity
increment.
| |||||||||||
Vector(int initialCapacity)
Constructs an empty vector with the specified initial capacity.
| |||||||||||
Vector()
Constructs an empty vector.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
synchronized void |
addElement(E obj)
Adds the specified component to the end of this vector, increasing its size
by one.
| ||||||||||
int |
capacity()
Returns the current capacity of this vector.
| ||||||||||
boolean |
contains(Object elem)
Tests if the specified object is a component in this vector.
| ||||||||||
synchronized void |
copyInto(Object[] anArray)
Copies the components of this vector into the specified array.
| ||||||||||
synchronized E |
elementAt(int index)
Returns the component at the specified index.
| ||||||||||
synchronized Enumeration<E> |
elements()
Returns an enumeration of the components of this vector.
| ||||||||||
synchronized void |
ensureCapacity(int minCapacity)
Increases the capacity of this vector, if necessary, to ensure that it can
hold at least the number of components specified by the minimum capacity
argument.
| ||||||||||
synchronized E |
firstElement()
Returns the first component of this vector.
| ||||||||||
E |
get(int index)
Returns the element at the specified position in this Vector.
| ||||||||||
int |
indexOf(Object elem)
Searches for the first occurrence of the given argument, testing for equality
using the
equals method. | ||||||||||
synchronized int |
indexOf(Object elem, int index)
Searches for the first occurrence of the given argument, beginning the search
at
index , and testing for equality using the equals
method. | ||||||||||
synchronized void |
insertElementAt(E obj, int index)
Inserts the specified object as a component in this vector at the specified
index . | ||||||||||
boolean |
isEmpty()
Tests if this vector has no components.
| ||||||||||
synchronized E |
lastElement()
Returns the last component of the vector.
| ||||||||||
int |
lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in this
vector.
| ||||||||||
synchronized int |
lastIndexOf(Object elem, int index)
Searches backwards for the specified object, starting from the specified
index, and returns an index to it.
| ||||||||||
synchronized void |
removeAllElements()
Removes all components from this vector and sets its size to zero.
| ||||||||||
synchronized boolean |
removeElement(Object obj)
Removes the first occurrence of the argument from this vector.
| ||||||||||
synchronized void |
removeElementAt(int index)
Deletes the component at the specified index.
| ||||||||||
synchronized void |
setElementAt(E obj, int index)
Sets the component at the specified
index of this vector to be
the specified object. | ||||||||||
synchronized void |
setSize(int newSize)
Sets the size of this vector.
| ||||||||||
int |
size()
Returns the number of components in this vector.
| ||||||||||
synchronized Object[] |
toArray()
Returns an array containing all of the elements in this Vector in the correct
order.
| ||||||||||
synchronized String |
toString()
Returns a string representation of this vector.
| ||||||||||
synchronized void |
trimToSize()
Trims the capacity of this vector to be the vector's current size.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
The amount by which the capacity of the vector is automatically incremented
when its size becomes greater than its capacity. If the capacity increment is
0
, the capacity of the vector is doubled each time it needs to
grow.
The number of valid components in the vector.
The array buffer into which the components of the vector are stored. The capacity of the vector is the length of this array buffer.
Constructs an empty vector with the specified initial capacity and capacity increment.
initialCapacity | the initial capacity of the vector. |
---|---|
capacityIncrement | the amount by which the capacity is increased when the vector overflows. |
IllegalArgumentException | if the specified initial capacity is negative |
---|
Constructs an empty vector with the specified initial capacity.
initialCapacity | the initial capacity of the vector. |
---|
Constructs an empty vector.
Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity.
obj | the component to be added. |
---|
Returns the current capacity of this vector.
Tests if the specified object is a component in this vector.
elem | an object. |
---|
true
if the specified object is a component in this
vector; false
otherwise.Copies the components of this vector into the specified array. The array must be big enough to hold all the objects in this vector.
anArray | the array into which the components get copied. |
---|
Returns the component at the specified index.
index | an index into this vector. |
---|
ArrayIndexOutOfBoundsException | if an invalid index was given. |
---|
Returns an enumeration of the components of this vector.
Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
minCapacity | the desired minimum capacity. |
---|
Returns the first component of this vector.
NoSuchElementException | if this vector has no components. |
---|
Returns the element at the specified position in this Vector.
index | index of the element to return |
---|
ArrayIndexOutOfBoundsException | if the index is out of range
(index < 0 || index >= size() ) |
---|
Searches for the first occurrence of the given argument, testing for equality
using the equals
method.
elem | an object. |
---|
-1
if the object is not found.Searches for the first occurrence of the given argument, beginning the search
at index
, and testing for equality using the equals
method.
elem | an object. |
---|---|
index | the index to start searching from. |
index
or later in the vector; returns
-1
if the object is not found.Inserts the specified object as a component in this vector at the specified
index
. Each component in this vector with an index greater or
equal to the specified index
is shifted upward to have an index
one greater than the value it had previously.
The index must be a value greater than or equal to 0
and less
than or equal to the current size of the vector.
obj | the component to insert. |
---|---|
index | where to insert the new component. |
ArrayIndexOutOfBoundsException | if the index was invalid. |
---|
Tests if this vector has no components.
true
if this vector has no components;
false
otherwise.Returns the last component of the vector.
size() - 1
.NoSuchElementException | if this vector is empty. |
---|
Returns the index of the last occurrence of the specified object in this vector.
elem | the desired component. |
---|
-1
if the object is not found.Searches backwards for the specified object, starting from the specified index, and returns an index to it.
elem | the desired component. |
---|---|
index | the index to start searching from. |
index
in the vector;
-1
if the object is not found.IndexOutOfBoundsException | if index is greater than or equal to the current size of this vector. |
---|
Removes all components from this vector and sets its size to zero.
Removes the first occurrence of the argument from this vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously.
obj | the component to be removed. |
---|
true
if the argument was a component of this vector;
false
otherwise.Deletes the component at the specified index. Each component in this vector
with an index greater or equal to the specified index
is shifted
downward to have an index one smaller than the value it had previously.
The index must be a value greater than or equal to 0
and less
than the current size of the vector.
index | the index of the object to remove. |
---|
ArrayIndexOutOfBoundsException | if the index was invalid. |
---|
Sets the component at the specified index
of this vector to be
the specified object. The previous component at that position is discarded.
The index must be a value greater than or equal to 0
and less
than the current size of the vector.
obj | what the component is to be set to. |
---|---|
index | the specified index. |
ArrayIndexOutOfBoundsException | if the index was invalid. |
---|
Sets the size of this vector. If the new size is greater than the current
size, new null
items are added to the end of the vector. If the
new size is less than the current size, all components at index
newSize
and greater are discarded.
newSize | the new size of this vector. |
---|
Returns the number of components in this vector.
Returns an array containing all of the elements in this Vector in the correct order.
ArrayList
Returns a string representation of this vector.
Trims the capacity of this vector to be the vector's current size. An application can use this operation to minimize the storage of a vector.