java.util.Vector<E>
Vector is a variable size contiguous indexable array of Objects. The size of
the Vector is the number of Objects it contains. The capacity of the Vector
is the number of Objects it can hold.
Objects may be inserted at any position up to the size of the Vector,
increasing the size of the Vector. Objects at any position in the Vector may
be removed, shrinking the size of the Vector. Objects at any position in the
Vector may be replaced, which does not affect the Vector size.
The capacity of a Vector may be specified when the Vector is created. If the
capacity of the Vector is exceeded, the capacity is increased, doubling by
default.
Known Direct Subclasses
| Stack<E> |
Stack is a Last-In/First-Out(LIFO) data structure which
represents a stack of objects. |
Summary
Fields
| protected |
|
|
int |
capacityIncrement |
How many elements should be added to the vector when it is detected that
it needs to grow to accommodate extra entries. |
| protected |
|
|
int |
elementCount |
The number of elements or the size of the vector. |
| protected |
|
|
Object[] |
elementData |
The elements of the vector. |
Public Constructors
Public Methods
Protected Methods
add,
add,
addAll,
clear,
equals,
get,
hashCode,
indexOf,
iterator,
lastIndexOf,
listIterator,
listIterator,
remove,
removeRange,
set,
subList
add,
addAll,
clear,
contains,
containsAll,
isEmpty,
iterator,
remove,
removeAll,
retainAll,
size,
toArray,
toArray,
toString
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
add,
addAll,
clear,
contains,
containsAll,
equals,
hashCode,
isEmpty,
iterator,
remove,
removeAll,
retainAll,
size,
toArray,
toArray
Methods inherited
from interface
java.util.List
add,
add,
addAll,
addAll,
clear,
contains,
containsAll,
equals,
get,
hashCode,
indexOf,
isEmpty,
iterator,
lastIndexOf,
listIterator,
listIterator,
remove,
remove,
removeAll,
retainAll,
set,
size,
subList,
toArray,
toArray
Details
Fields
protected
int
capacityIncrement
How many elements should be added to the vector when it is detected that
it needs to grow to accommodate extra entries.
protected
int
elementCount
The number of elements or the size of the vector.
protected
Object[]
elementData
The elements of the vector.
Public Constructors
public
Vector()
Constructs a new Vector using the default capacity.
public
Vector(int capacity)
Constructs a new Vector using the specified capacity.
Parameters
| capacity
| the initial capacity of the new vector
|
public
Vector(int capacity, int capacityIncrement)
Constructs a new Vector using the specified capacity and capacity
increment.
Parameters
| capacity
| the initial capacity of the new Vector |
| capacityIncrement
| the amount to increase the capacity when this Vector is full
|
public
Vector(Collection<? extends E> collection)
Constructs a new instance of
Vector containing the
elements in
collection. The order of the elements in the
new
Vector is dependent on the iteration order of the seed
collection.
Parameters
| collection
| the collection of elements to add
|
Public Methods
public
void
add(int location, E object)
Adds the specified object into this Vector at the specified location. The
object is inserted before any previous element at the specified location.
If the location is equal to the size of this Vector, the object is added
at the end.
Parameters
| location
| the index at which to insert the element |
| object
| the object to insert in this Vector |
public
boolean
add(E object)
Adds the specified object at the end of this Vector.
Parameters
| object
| the object to add to the Vector |
public
synchronized
boolean
addAll(int location, Collection<? extends E> collection)
Inserts the objects in the specified Collection at the specified location
in this Vector. The objects are inserted in the order in which they are
returned from the Collection iterator.
Parameters
| location
| the location to insert the objects |
| collection
| the Collection of objects |
Returns
- true if this Vector is modified, false otherwise
public
synchronized
boolean
addAll(Collection<? extends E> collection)
Adds the objects in the specified Collection to the end of this Vector.
Parameters
| collection
| the Collection of objects |
Returns
- true if this Vector is modified, false otherwise
public
synchronized
void
addElement(E object)
Adds the specified object at the end of this Vector.
Parameters
| object
| the object to add to the Vector
|
public
synchronized
int
capacity()
Returns the number of elements this Vector can hold without growing.
Returns
- the capacity of this Vector
public
void
clear()
Removes all elements from this Vector, leaving it empty.
public
synchronized
Object
clone()
Returns a new Vector with the same elements, size, capacity and capacity
increment as this Vector.
Returns
- a shallow copy of this Vector
public
boolean
contains(Object object)
Searches this Vector for the specified object.
Parameters
| object
| the object to look for in this Vector |
Returns
- true if object is an element of this Vector, false otherwise
public
synchronized
boolean
containsAll(Collection<?> collection)
Searches this Vector for all objects in the specified Collection.
Parameters
| collection
| the Collection of objects |
Returns
- true if all objects in the specified Collection are elements of
this Vector, false otherwise
public
synchronized
void
copyInto(Object[] elements)
Attempts to copy elements contained by this
Vector into
the corresponding elements of the supplied
Object array.
Parameters
| elements
| the Object array into which the elements of
this Vector are copied |
public
synchronized
E
elementAt(int location)
Returns the element at the specified location in this Vector.
Parameters
| location
| the index of the element to return in this Vector |
Returns
- the element at the specified location
Returns an Enumeration on the elements of this Vector. The results of the
Enumeration may be affected if the contents of this Vector are modified.
Returns
- an Enumeration of the elements of this Vector
public
synchronized
void
ensureCapacity(int minimumCapacity)
Ensures that this Vector can hold the specified number of elements
without growing.
Parameters
| minimumCapacity
| the minimum number of elements that this vector will hold
before growing |