Methods Summary |
---|
public synchronized boolean | add(E e)Appends the specified element to the end of this Vector.
modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = e;
return true;
|
public void | add(int index, E element)Inserts the specified element at the specified position in this Vector.
Shifts the element currently at that position (if any) and any
subsequent elements to the right (adds one to their indices).
insertElementAt(element, index);
|
public synchronized boolean | addAll(java.util.Collection c)Appends all of the elements in the specified Collection to the end of
this Vector, in the order that they are returned by the specified
Collection's Iterator. The behavior of this operation is undefined if
the specified Collection is modified while the operation is in progress.
(This implies that the behavior of this call is undefined if the
specified Collection is this Vector, and this Vector is nonempty.)
modCount++;
Object[] a = c.toArray();
int numNew = a.length;
ensureCapacityHelper(elementCount + numNew);
System.arraycopy(a, 0, elementData, elementCount, numNew);
elementCount += numNew;
return numNew != 0;
|
public synchronized boolean | addAll(int index, java.util.Collection c)Inserts all of the elements in the specified Collection into this
Vector at the specified position. Shifts the element currently at
that position (if any) and any subsequent elements to the right
(increases their indices). The new elements will appear in the Vector
in the order that they are returned by the specified Collection's
iterator.
modCount++;
if (index < 0 || index > elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object[] a = c.toArray();
int numNew = a.length;
ensureCapacityHelper(elementCount + numNew);
int numMoved = elementCount - index;
if (numMoved > 0)
System.arraycopy(elementData, index, elementData, index + numNew,
numMoved);
System.arraycopy(a, 0, elementData, index, numNew);
elementCount += numNew;
return numNew != 0;
|
public synchronized void | addElement(E 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.
This method is identical in functionality to the
{@link #add(Object) add(E)}
method (which is part of the {@link List} interface).
modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = obj;
|
public synchronized int | capacity()Returns the current capacity of this vector.
return elementData.length;
|
public void | clear()Removes all of the elements from this Vector. The Vector will
be empty after this call returns (unless it throws an exception).
removeAllElements();
|
public synchronized java.lang.Object | clone()Returns a clone of this vector. The copy will contain a
reference to a clone of the internal data array, not a reference
to the original internal data array of this {@code Vector} object.
try {
Vector<E> v = (Vector<E>) super.clone();
v.elementData = Arrays.copyOf(elementData, elementCount);
v.modCount = 0;
return v;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
|
public boolean | contains(java.lang.Object o)Returns {@code true} if this vector contains the specified element.
More formally, returns {@code true} if and only if this vector
contains at least one element {@code e} such that
(o==null ? e==null : o.equals(e)).
return indexOf(o, 0) >= 0;
|
public synchronized boolean | containsAll(java.util.Collection c)Returns true if this Vector contains all of the elements in the
specified Collection.
return super.containsAll(c);
|
public synchronized void | copyInto(java.lang.Object[] anArray)Copies the components of this vector into the specified array.
The item at index {@code k} in this vector is copied into
component {@code k} of {@code anArray}.
System.arraycopy(elementData, 0, anArray, 0, elementCount);
|
public synchronized E | elementAt(int index)Returns the component at the specified index.
This method is identical in functionality to the {@link #get(int)}
method (which is part of the {@link List} interface).
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
}
return (E)elementData[index];
|
public java.util.Enumeration | elements()Returns an enumeration of the components of this vector. The
returned {@code Enumeration} object will generate all items in
this vector. The first item generated is the item at index {@code 0},
then the item at index {@code 1}, and so on.
return new Enumeration<E>() {
int count = 0;
public boolean hasMoreElements() {
return count < elementCount;
}
public E nextElement() {
synchronized (Vector.this) {
if (count < elementCount) {
return (E)elementData[count++];
}
}
throw new NoSuchElementException("Vector Enumeration");
}
};
|
public 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.
If the current capacity of this vector is less than
{@code minCapacity}, then its capacity is increased by replacing its
internal data array, kept in the field {@code elementData}, with a
larger one. The size of the new data array will be the old size plus
{@code capacityIncrement}, unless the value of
{@code capacityIncrement} is less than or equal to zero, in which case
the new capacity will be twice the old capacity; but if this new size
is still smaller than {@code minCapacity}, then the new capacity will
be {@code minCapacity}.
modCount++;
ensureCapacityHelper(minCapacity);
|
private void | ensureCapacityHelper(int minCapacity)This implements the unsynchronized semantics of ensureCapacity.
Synchronized methods in this class can internally call this
method for ensuring capacity without incurring the cost of an
extra synchronization.
int oldCapacity = elementData.length;
if (minCapacity > oldCapacity) {
Object[] oldData = elementData;
int newCapacity = (capacityIncrement > 0) ?
(oldCapacity + capacityIncrement) : (oldCapacity * 2);
if (newCapacity < minCapacity) {
newCapacity = minCapacity;
}
elementData = Arrays.copyOf(elementData, newCapacity);
}
|
public synchronized boolean | equals(java.lang.Object o)Compares the specified Object with this Vector for equality. Returns
true if and only if the specified Object is also a List, both Lists
have the same size, and all corresponding pairs of elements in the two
Lists are equal. (Two elements {@code e1} and
{@code e2} are equal if {@code (e1==null ? e2==null :
e1.equals(e2))}.) In other words, two Lists are defined to be
equal if they contain the same elements in the same order.
return super.equals(o);
|
public synchronized E | firstElement()Returns the first component (the item at index {@code 0}) of
this vector.
if (elementCount == 0) {
throw new NoSuchElementException();
}
return (E)elementData[0];
|
public synchronized E | get(int index)Returns the element at the specified position in this Vector.
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
return (E)elementData[index];
|
public synchronized int | hashCode()Returns the hash code value for this Vector.
return super.hashCode();
|
public int | indexOf(java.lang.Object o)Returns the index of the first occurrence of the specified element
in this vector, or -1 if this vector does not contain the element.
More formally, returns the lowest index {@code i} such that
(o==null ? get(i)==null : o.equals(get(i))),
or -1 if there is no such index.
return indexOf(o, 0);
|
public synchronized int | indexOf(java.lang.Object o, int index)Returns the index of the first occurrence of the specified element in
this vector, searching forwards from {@code index}, or returns -1 if
the element is not found.
More formally, returns the lowest index {@code i} such that
(i >= index && (o==null ? get(i)==null : o.equals(get(i)))),
or -1 if there is no such index.
if (o == null) {
for (int i = index ; i < elementCount ; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = index ; i < elementCount ; i++)
if (o.equals(elementData[i]))
return i;
}
return -1;
|
public synchronized void | insertElementAt(E obj, int index)Inserts the specified object as a component in this vector at the
specified {@code index}. Each component in this vector with
an index greater or equal to the specified {@code 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 {@code 0}
and less than or equal to the current size of the vector. (If the
index is equal to the current size of the vector, the new element
is appended to the Vector.)
This method is identical in functionality to the
{@link #add(int, Object) add(int, E)}
method (which is part of the {@link List} interface). Note that the
{@code add} method reverses the order of the parameters, to more closely
match array usage.
modCount++;
if (index > elementCount) {
throw new ArrayIndexOutOfBoundsException(index
+ " > " + elementCount);
}
ensureCapacityHelper(elementCount + 1);
System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
elementData[index] = obj;
elementCount++;
|
public synchronized boolean | isEmpty()Tests if this vector has no components.
return elementCount == 0;
|
public synchronized E | lastElement()Returns the last component of the vector.
if (elementCount == 0) {
throw new NoSuchElementException();
}
return (E)elementData[elementCount - 1];
|
public synchronized int | lastIndexOf(java.lang.Object o)Returns the index of the last occurrence of the specified element
in this vector, or -1 if this vector does not contain the element.
More formally, returns the highest index {@code i} such that
(o==null ? get(i)==null : o.equals(get(i))),
or -1 if there is no such index.
return lastIndexOf(o, elementCount-1);
|
public synchronized int | lastIndexOf(java.lang.Object o, int index)Returns the index of the last occurrence of the specified element in
this vector, searching backwards from {@code index}, or returns -1 if
the element is not found.
More formally, returns the highest index {@code i} such that
(i <= index && (o==null ? get(i)==null : o.equals(get(i)))),
or -1 if there is no such index.
if (index >= elementCount)
throw new IndexOutOfBoundsException(index + " >= "+ elementCount);
if (o == null) {
for (int i = index; i >= 0; i--)
if (elementData[i]==null)
return i;
} else {
for (int i = index; i >= 0; i--)
if (o.equals(elementData[i]))
return i;
}
return -1;
|
public boolean | remove(java.lang.Object o)Removes the first occurrence of the specified element in this Vector
If the Vector does not contain the element, it is unchanged. More
formally, removes the element with the lowest index i such that
{@code (o==null ? get(i)==null : o.equals(get(i)))} (if such
an element exists).
return removeElement(o);
|
public synchronized E | remove(int index)Removes the element at the specified position in this Vector.
Shifts any subsequent elements to the left (subtracts one from their
indices). Returns the element that was removed from the Vector.
modCount++;
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object oldValue = elementData[index];
int numMoved = elementCount - index - 1;
if (numMoved > 0)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
elementData[--elementCount] = null; // Let gc do its work
return (E)oldValue;
|
public synchronized boolean | removeAll(java.util.Collection c)Removes from this Vector all of its elements that are contained in the
specified Collection.
return super.removeAll(c);
|
public synchronized void | removeAllElements()Removes all components from this vector and sets its size to zero.
This method is identical in functionality to the {@link #clear}
method (which is part of the {@link List} interface).
modCount++;
// Let gc do its work
for (int i = 0; i < elementCount; i++)
elementData[i] = null;
elementCount = 0;
|
public synchronized boolean | removeElement(java.lang.Object obj)Removes the first (lowest-indexed) 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.
This method is identical in functionality to the
{@link #remove(Object)} method (which is part of the
{@link List} interface).
modCount++;
int i = indexOf(obj);
if (i >= 0) {
removeElementAt(i);
return true;
}
return false;
|
public 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
{@code index} is shifted downward to have an index one
smaller than the value it had previously. The size of this vector
is decreased by {@code 1}.
The index must be a value greater than or equal to {@code 0}
and less than the current size of the vector.
This method is identical in functionality to the {@link #remove(int)}
method (which is part of the {@link List} interface). Note that the
{@code remove} method returns the old value that was stored at the
specified position.
modCount++;
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(index + " >= " +
elementCount);
}
else if (index < 0) {
throw new ArrayIndexOutOfBoundsException(index);
}
int j = elementCount - index - 1;
if (j > 0) {
System.arraycopy(elementData, index + 1, elementData, index, j);
}
elementCount--;
elementData[elementCount] = null; /* to let gc do its work */
|
protected synchronized void | removeRange(int fromIndex, int toIndex)Removes from this List all of the elements whose index is between
fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding
elements to the left (reduces their index).
This call shortens the ArrayList by (toIndex - fromIndex) elements. (If
toIndex==fromIndex, this operation has no effect.)
modCount++;
int numMoved = elementCount - toIndex;
System.arraycopy(elementData, toIndex, elementData, fromIndex,
numMoved);
// Let gc do its work
int newElementCount = elementCount - (toIndex-fromIndex);
while (elementCount != newElementCount)
elementData[--elementCount] = null;
|
public synchronized boolean | retainAll(java.util.Collection c)Retains only the elements in this Vector that are contained in the
specified Collection. In other words, removes from this Vector all
of its elements that are not contained in the specified Collection.
return super.retainAll(c);
|
public synchronized E | set(int index, E element)Replaces the element at the specified position in this Vector with the
specified element.
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object oldValue = elementData[index];
elementData[index] = element;
return (E)oldValue;
|
public synchronized void | setElementAt(E obj, int index)Sets the component at the specified {@code 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 {@code 0}
and less than the current size of the vector.
This method is identical in functionality to the
{@link #set(int, Object) set(int, E)}
method (which is part of the {@link List} interface). Note that the
{@code set} method reverses the order of the parameters, to more closely
match array usage. Note also that the {@code set} method returns the
old value that was stored at the specified position.
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(index + " >= " +
elementCount);
}
elementData[index] = obj;
|
public synchronized void | setSize(int newSize)Sets the size of this vector. If the new size is greater than the
current size, new {@code null} items are added to the end of
the vector. If the new size is less than the current size, all
components at index {@code newSize} and greater are discarded.
modCount++;
if (newSize > elementCount) {
ensureCapacityHelper(newSize);
} else {
for (int i = newSize ; i < elementCount ; i++) {
elementData[i] = null;
}
}
elementCount = newSize;
|
public synchronized int | size()Returns the number of components in this vector.
return elementCount;
|
public synchronized java.util.List | subList(int fromIndex, int toIndex)Returns a view of the portion of this List between fromIndex,
inclusive, and toIndex, exclusive. (If fromIndex and toIndex are
equal, the returned List is empty.) The returned List is backed by this
List, so changes in the returned List are reflected in this List, and
vice-versa. The returned List supports all of the optional List
operations supported by this List.
This method eliminates the need for explicit range operations (of
the sort that commonly exist for arrays). Any operation that expects
a List can be used as a range operation by operating on a subList view
instead of a whole List. For example, the following idiom
removes a range of elements from a List:
list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf,
and all of the algorithms in the Collections class can be applied to
a subList.
The semantics of the List returned by this method become undefined if
the backing list (i.e., this List) is structurally modified in
any way other than via the returned List. (Structural modifications are
those that change the size of the List, or otherwise perturb it in such
a fashion that iterations in progress may yield incorrect results.)
return Collections.synchronizedList(super.subList(fromIndex, toIndex),
this);
|
public synchronized java.lang.Object[] | toArray()Returns an array containing all of the elements in this Vector
in the correct order.
return Arrays.copyOf(elementData, elementCount);
|
public synchronized T[] | toArray(T[] a)Returns an array containing all of the elements in this Vector in the
correct order; the runtime type of the returned array is that of the
specified array. If the Vector fits in the specified array, it is
returned therein. Otherwise, a new array is allocated with the runtime
type of the specified array and the size of this Vector.
If the Vector fits in the specified array with room to spare
(i.e., the array has more elements than the Vector),
the element in the array immediately following the end of the
Vector is set to null. (This is useful in determining the length
of the Vector only if the caller knows that the Vector
does not contain any null elements.)
if (a.length < elementCount)
return (T[]) Arrays.copyOf(elementData, elementCount, a.getClass());
System.arraycopy(elementData, 0, a, 0, elementCount);
if (a.length > elementCount)
a[elementCount] = null;
return a;
|
public synchronized java.lang.String | toString()Returns a string representation of this Vector, containing
the String representation of each element.
return super.toString();
|
public synchronized void | trimToSize()Trims the capacity of this vector to be the vector's current
size. If the capacity of this vector is larger than its current
size, then the capacity is changed to equal the size by replacing
its internal data array, kept in the field {@code elementData},
with a smaller one. An application can use this operation to
minimize the storage of a vector.
modCount++;
int oldCapacity = elementData.length;
if (elementCount < oldCapacity) {
elementData = Arrays.copyOf(elementData, elementCount);
}
|
private synchronized void | writeObject(java.io.ObjectOutputStream s)Save the state of the {@code Vector} instance to a stream (that
is, serialize it). This method is present merely for synchronization.
It just calls the default writeObject method.
s.defaultWriteObject();
|