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.
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.
The array buffer into which the components of the vector are
stored. The capacity of the vector is the length of this array buffer.
elementCount
protected int elementCount
The number of valid components in the vector.
capacityIncrement
protected int capacityIncrement
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.
Vector
public Vector(int initialCapacity,
int capacityIncrement)
Constructs an empty vector with the specified initial capacity and
capacity increment.
Parameters:
initialCapacity - the initial capacity of the vector.
capacityIncrement - the amount by which the capacity is
increased when the vector overflows.
Vector
public Vector(int initialCapacity)
Constructs an empty vector with the specified initial capacity.
Parameters:
initialCapacity - the initial capacity of the vector.
public final 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.
public final synchronized void setSize(int newSize)
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.
public final synchronized int indexOf(Object elem,
int index)
Searches for the first occurence of the given argument, beginning
the search at index, and testing for equality using
the equals method.
Parameters:
elem - an object.
index - the index to start searching from.
Returns:
the index of the first occurrence of the object argument in
this vector at position index or later in the
vector; returns -1 if the object is not found.
public final synchronized void removeElementAt(int index)
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.
public final synchronized void insertElementAt(Object obj,
int index)
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.
public final synchronized void addElement(Object obj)
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.
public final synchronized boolean removeElement(Object obj)
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.
Parameters:
obj - the component to be removed.
Returns:
true if the argument was a component of this
vector; false otherwise.
Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.