加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090218033606/http://developer.android.com:80/reference/java/util/Vector.html
public class

Vector

extends AbstractList<E>
implements Serializable Cloneable List<E> RandomAccess
java.lang.Object
   ↳ java.util.AbstractCollection<E>
     ↳ java.util.AbstractList<E>
       ↳ java.util.Vector<E>
Known Direct Subclasses

Class Overview

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.

See Also

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.
[Expand]
Inherited Fields
From class java.util.AbstractList
Public Constructors
Vector()
Constructs a new Vector using the default capacity.
Vector(int capacity)
Constructs a new Vector using the specified capacity.
Vector(int capacity, int capacityIncrement)
Constructs a new Vector using the specified capacity and capacity increment.
Vector(Collection<? extends E> collection)
Constructs a new instance of Vector containing the elements in collection.
Public Methods
void add(int location, E object)
Adds the specified object into this Vector at the specified location.
boolean add(E object)
Adds the specified object at the end of this Vector.
synchronized boolean addAll(int location, Collection<? extends E> collection)
Inserts the objects in the specified Collection at the specified location in this Vector.
synchronized boolean addAll(Collection<? extends E> collection)
Adds the objects in the specified Collection to the end of this Vector.
synchronized void addElement(E object)
Adds the specified object at the end of this Vector.
synchronized int capacity()
Returns the number of elements this Vector can hold without growing.
void clear()
Removes all elements from this Vector, leaving it empty.
synchronized Object clone()
Returns a new Vector with the same elements, size, capacity and capacity increment as this Vector.
boolean contains(Object object)
Searches this Vector for the specified object.
synchronized boolean containsAll(Collection<?> collection)
Searches this Vector for all objects in the specified Collection.
synchronized void copyInto(Object[] elements)
Attempts to copy elements contained by this Vector into the corresponding elements of the supplied Object array.
synchronized E elementAt(int location)
Returns the element at the specified location in this Vector.
Enumeration<E> elements()
Returns an Enumeration on the elements of this Vector.
synchronized void ensureCapacity(int minimumCapacity)
Ensures that this Vector can hold the specified number of elements without growing.
synchronized boolean equals(Object object)
Compares the specified object to this Vector and answer if they are equal.
synchronized E firstElement()
Returns the first element in this Vector.
synchronized E get(int location)
Returns the element at the specified location in this Vector.
synchronized int hashCode()
Returns an integer hash code for the receiver.
int indexOf(Object object)
Searches in this Vector for the index of the specified object.
synchronized int indexOf(Object object, int location)
Searches in this Vector for the index of the specified object.
synchronized void insertElementAt(E object, int location)
Inserts the specified object into this Vector at the specified location.
synchronized boolean isEmpty()
Returns if this Vector has no elements, a size of zero.
synchronized E lastElement()
Returns the last element in this Vector.
synchronized int lastIndexOf(Object object, int location)
Searches in this Vector for the index of the specified object.
synchronized int lastIndexOf(Object object)
Searches in this Vector for the index of the specified object.
synchronized E remove(int location)
Removes the object at the specified location from this List.
boolean remove(Object object)
Removes the first occurrence, starting at the beginning and moving towards the end, of the specified object from this Vector.
synchronized boolean removeAll(Collection<?> collection)
Removes all occurrences in this Vector of each object in the specified Collection.
synchronized void removeAllElements()
Removes all elements from this Vector, leaving the size zero and the capacity unchanged.
synchronized boolean removeElement(Object object)
Removes the first occurrence, starting at the beginning and moving towards the end, of the specified object from this Vector.
synchronized void removeElementAt(int location)
Removes the element found at index position location from this Vector and decrements the size accordingly.
synchronized boolean retainAll(Collection<?> collection)
Removes all objects from this Vector that are not contained in the specified Collection.
synchronized E set(int location, E object)
Replaces the element at the specified location in this Vector with the specified object.
synchronized void setElementAt(E object, int location)
Replaces the element at the specified location in this Vector with the specified object.
synchronized void setSize(int length)
Sets the size of this Vector to the specified size.
synchronized int size()
Returns the number of elements in this Vector.
synchronized List<E> subList(int start, int end)
Returns a List of the specified portion of this Vector from the start index to one less than the end index.
synchronized <T> T[] toArray(T[] contents)
Returns an array containing all elements contained in this Vector.
synchronized Object[] toArray()
Returns a new array containing all elements contained in this Vector.
synchronized String toString()
Returns the string representation of this Vector.
synchronized void trimToSize()
Sets the capacity of this Vector to be the same as the size.
Protected Methods
void removeRange(int start, int end)
Removes the objects in the specified range from the start to the, but not including, end index.
[Expand]
Inherited Methods
From class java.util.AbstractList
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface java.util.List

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
Throws
ArrayIndexOutOfBoundsException when location < 0 || > size()

public boolean add (E object)

Adds the specified object at the end of this Vector.

Parameters
object the object to add to the Vector
Returns
  • true

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
Throws
ArrayIndexOutOfBoundsException when location < 0 or location > size()

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.

See Also

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
See Also

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
See Also

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
Throws
ArrayIndexOutOfBoundsException when location < 0 || >= size()
See Also

public Enumeration<E> elements ()

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
See Also

public synchronized boolean equals (Object object)

Compares the specified object to this Vector and answer if they are equal. The object must be a List which contains the same objects in the same order.

Parameters
object the object to compare with this object
Returns
  • true if the specified object is equal to this Vector, false otherwise
See Also

public synchronized E firstElement ()

Returns the first element in this Vector.

Returns
  • the element at the first position
Throws
NoSuchElementException when this vector is empty

public synchronized E get (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
Throws
ArrayIndexOutOfBoundsException when location < 0 || >= size()
See Also

public synchronized int hashCode ()

Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Returns
  • the receiver's hash
See Also

public int indexOf (Object object)

Searches in this Vector for the index of the specified object. The search for the object starts at the beginning and moves towards the end of this Vector.

Parameters
object the object to find in this Vector
Returns
  • the index in this Vector of the specified element, -1 if the element isn't found

public synchronized int indexOf (Object object, int location)

Searches in this Vector for the index of the specified object. The search for the object starts at the specified location and moves towards the end of this Vector.

Parameters
object the object to find in this Vector
location the index at which to start searching
Returns
  • the index in this Vector of the specified element, -1 if the element isn't found
Throws
ArrayIndexOutOfBoundsException when location < 0

public synchronized void insertElementAt (E object, int location)

Inserts the specified object into this Vector at the specified location. This 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
object the object to insert in this Vector
location the index at which to insert the element
Throws
ArrayIndexOutOfBoundsException when location < 0 || > size()

public synchronized boolean isEmpty ()

Returns if this Vector has no elements, a size of zero.

Returns
  • true if this Vector has no elements, false otherwise
See Also

public synchronized E lastElement ()

Returns the last element in this Vector.

Returns
  • the element at the last position
Throws
NoSuchElementException when this vector is empty

public synchronized int lastIndexOf (Object object, int location)

Searches in this Vector for the index of the specified object. The search for the object starts at the specified location and moves towards the start of this Vector.

Parameters
object the object to find in this Vector
location the index at which to start searching
Returns
  • the index in this Vector of the specified element, -1 if the element isn't found
Throws
ArrayIndexOutOfBoundsException when location >= size()

public synchronized int lastIndexOf (Object object)

Searches in this Vector for the index of the specified object. The search for the object starts at the end and moves towards the start of this Vector.

Parameters
object the object to find in this Vector
Returns
  • the index in this Vector of the specified element, -1 if the element isn't found

public synchronized E remove (int location)

Removes the object at the specified location from this List.

Parameters
location the index of the object to remove
Returns
  • the removed object

public boolean remove (Object object)

Removes the first occurrence, starting at the beginning and moving towards the end, of the specified object from this Vector.

Parameters
object the object to remove from this Vector
Returns
  • true if the specified object was found, false otherwise

public synchronized boolean removeAll (Collection<?> collection)

Removes all occurrences in this Vector of each object in the specified Collection.

Parameters
collection the Collection of objects to remove
Returns
  • true if this Vector is modified, false otherwise

public synchronized void removeAllElements ()

Removes all elements from this Vector, leaving the size zero and the capacity unchanged.

See Also

public synchronized boolean removeElement (Object object)

Removes the first occurrence, starting at the beginning and moving towards the end, of the specified object from this Vector.

Parameters
object the object to remove from this Vector
Returns
  • true if the specified object was found, false otherwise

public synchronized void removeElementAt (int location)

Removes the element found at index position location from this Vector and decrements the size accordingly.

Parameters
location the index of the element to remove
Throws
ArrayIndexOutOfBoundsException when location < 0 || >= size()

public synchronized boolean retainAll (Collection<?> collection)

Removes all objects from this Vector that are not contained in the specified Collection.

Parameters
collection the Collection of objects to retain
Returns
  • true if this Vector is modified, false otherwise

public synchronized E set (int location, E object)

Replaces the element at the specified location in this Vector with the specified object.

Parameters
location the index at which to put the specified object
object the object to add to this Vector
Returns
  • the previous element at the location
Throws
ArrayIndexOutOfBoundsException when location < 0 || >= size()
See Also

public synchronized void setElementAt (E object, int location)

Replaces the element at the specified location in this Vector with the specified object.

Parameters
object the object to add to this Vector
location the index at which to put the specified object
Throws
ArrayIndexOutOfBoundsException when location < 0 || >= size()
See Also

public synchronized void setSize (int length)

Sets the size of this Vector to the specified size. If there are more than length elements in this Vector, the elements at end are lost. If there are less than length elements in the Vector, the additional elements contain null.

Parameters
length the new size of this Vector
See Also

public synchronized int size ()

Returns the number of elements in this Vector.

Returns
  • the number of elements in this Vector

public synchronized List<E> subList (int start, int end)

Returns a List of the specified portion of this Vector from the start index to one less than the end index. The returned List is backed by this Vector so changes to one are reflected by the other.

Parameters
start the index at which to start the sublist
end the index one past the end of the sublist
Returns
  • a List of a portion of this Vector
Throws
IndexOutOfBoundsException when start < 0 or end > size()
IllegalArgumentException when start > end

public synchronized T[] toArray (T[] contents)

Returns an array containing all elements contained in this Vector. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this Vector, the array element following the collection elements is set to null.

Parameters
contents the array
Returns
  • an array of the elements from this Vector
Throws
ArrayStoreException when the type of an element in this Vector cannot be stored in the type of the specified array

public synchronized Object[] toArray ()

Returns a new array containing all elements contained in this Vector.

Returns
  • an array of the elements from this Vector

public synchronized String toString ()

Returns the string representation of this Vector.

Returns
  • the string representation of this Vector
See Also

public synchronized void trimToSize ()

Sets the capacity of this Vector to be the same as the size.

Protected Methods

protected void removeRange (int start, int end)

Removes the objects in the specified range from the start to the, but not including, end index.

Parameters
start the index at which to start removing
end the index one past the end of the range to remove
Throws
IndexOutOfBoundsException when start < 0, start > end or end > size()