Java Reference
In-Depth Information
CONSTRUCTORS
public Vector()
Creates an empty vector with an initial capacity of 10 . When the vector needs to increase its
capacity, the capacity doubles.
public Vector(Collection<? extends T> c)
Creates a vector that contains all the elements of the collection c in the same order as they have
in c . If c is a vector, the capacity of the created vector will be c.size(), not c.capacity .
Throws:
NullPointerException if c is null.
public Vector( int initialCapacity)
Creates an empty vector with the specifi ed initial capacity. When the vector needs to increase its
capacity, the capacity doubles.
public Vector( int initialCapacity, int capacityIncrement)
Constructs an empty vector with the specifi ed initial capacity and capacity increment. When the
vector needs to grow, it will add room for capacityIncrement more items.
ARRAYLIKE METHODS
public T get( int index)
Returns the element at the specifi ed index. This is analogous to returning a[index] for an array a .
Throws:
ArrayIndexOutOfBoundsException if the index is not greater than or equal to 0 and less
than the current size of the vector.
public T set( int index, T newElement)
Sets the element at the specifi ed index to newElement . The element previously at that position
is returned. If you draw an analogy between the vector and an array a , this is analogous to setting
a[index] to the value newElement .
Throws:
ArrayIndexOutOfBoundsException if the index is not greater than or equal to 0 and
strictly less than the current size of the vector.
METHODS TO ADD ELEMENTS
public void add( int index, T newElement)
Inserts newElement as an element in the calling vector at the specifi ed index. Each element in
the vector with an index greater or equal to index is shifted upward to have an index that is one
greater than the value it had previously.
Note that you can use this method to add an element after the last current element. The capacity
of the vector is increased if this is required.
Throws:
ArrayIndexOutOfBoundsException if the index is not greater than or equal to 0 and less
than or equal to the current size of the vector.
Search WWH ::




Custom Search