|
Final | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.Vector<E>
public class 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.
StringBuffer,
Serialized Form| Field Summary | |
|---|---|
protected int |
capacityIncrement
The amount by which the capacity of the vector is increased. |
protected int |
elementCount
The number of elements or the size of the vector. |
protected Object[] |
elementData
The elements of the vector. |
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
Vector()
Constructs a new Vector using the default capacity. |
|
Vector(Collection<? extends E> collection)
Constructs a new instance of Vector containing the elements in the specified collection. |
|
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. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(E object)
Adds the specified object at the end of this Vector. |
|
void |
add(int location,
E object)
Adds the specified object into this Vector at the specified location. |
|
boolean |
addAll(Collection<? extends E> collection)
Adds the objects in the specified Collection to the end of this Vector. |
|
boolean |
addAll(int location,
Collection<? extends E> collection)
Inserts the objects in the specified Collection at the specified location in this Vector. |
|
void |
addElement(E object)
Adds the specified object at the end of this Vector. |
|
int |
capacity()
Answers the number of elements this Vector can hold without growing. |
|
void |
clear()
Removes all elements from this Vector, leaving it empty. |
|
Object |
clone()
Answers 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. |
|
boolean |
containsAll(Collection<?> collection)
Searches this Vector for all objects in the specified Collection. |
|
void |
copyInto(Object[] elements)
Copies the elements of this Vector into the specified Object array. |
|
E |
elementAt(int location)
Answers the element at the specified location in this Vector. |
|
Enumeration<E> |
elements()
Answers an Enumeration on the elements of this Vector. |
|
void |
ensureCapacity(int minimumCapacity)
Ensures that this Vector can hold the specified number of elements without growing. |
|
boolean |
equals(Object object)
Compares the specified object to this Vector and answer if they are equal. |
|
E |
firstElement()
Answers the first element in this Vector. |
|
E |
get(int location)
Answers the element at the specified location in this Vector. |
|
int |
hashCode()
Answers an integer hash code for the receiver. |
|
int |
indexOf(Object object)
Searches in this Vector for the index of the specified object. |
|
int |
indexOf(Object object,
int location)
Searches in this Vector for the index of the specified object. |
|
void |
insertElementAt(E object,
int location)
Inserts the specified object into this Vector at the specified location. |
|
boolean |
isEmpty()
Answers if this Vector has no elements, a size of zero. |
|
E |
lastElement()
Answers the last element in this Vector. |
|
int |
lastIndexOf(Object object)
Searches in this Vector for the index of the specified object. |
|
int |
lastIndexOf(Object object,
int location)
Searches in this Vector for the index of the specified object. |
|
E |
remove(int location)
Removes the element at the specified location from this Vector. |
|
boolean |
remove(Object object)
Removes the first occurrence, starting at the beginning and moving towards the end, of the specified object from this Vector. |
|
boolean |
removeAll(Collection<?> collection)
Removes all occurrences in this Vector of each object in the specified Collection. |
|
void |
removeAllElements()
Removes all elements from this Vector, leaving the size zero and the capacity unchanged. |
|
boolean |
removeElement(Object object)
Removes the first occurrence, starting at the beginning and moving towards the end, of the specified object from this Vector. |
|
void |
removeElementAt(int location)
Removes the element at the specified location from this Vector. |
|
protected void |
removeRange(int start,
int end)
Removes the objects in the specified range from the start to the, but not including, end index. |
|
boolean |
retainAll(Collection<?> collection)
Removes all objects from this Vector that are not contained in the specified Collection. |
|
E |
set(int location,
E object)
Replaces the element at the specified location in this Vector with the specified object. |
|
void |
setElementAt(E object,
int location)
Replaces the element at the specified location in this Vector with the specified object. |
|
void |
setSize(int length)
Sets the size of this Vector to the specified size. |
|
int |
size()
Answers the number of elements in this Vector. |
|
List<E> |
subList(int start,
int end)
Answers a List of the specified portion of this Vector from the start index to one less than the end index. |
|
Object[] |
toArray()
Answers a new array containing all elements contained in this Vector. |
|
|
toArray(T[] contents)
Answers an array containing all elements contained in this Vector. |
|
String |
toString()
Answers the string representation of this Vector. |
|
void |
trimToSize()
Sets the capacity of this Vector to be the same as the size. |
|
| Methods inherited from class java.util.AbstractList |
|---|
iterator, listIterator, listIterator |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
iterator, listIterator, listIterator |
| Field Detail |
|---|
protected int elementCount
protected Object[] elementData
protected int capacityIncrement
| Constructor Detail |
|---|
public Vector()
public Vector(int capacity)
capacity - the initial capacity of the new vectorpublic Vector(int capacity,
int capacityIncrement)
capacity - the initial capacity of the new VectorcapacityIncrement - the amount to increase the capacity
when this Vector is fullpublic Vector(Collection<? extends E> collection)
collection - the collection of elements to add| Method Detail |
|---|
public void add(int location,
E object)
add in interface List<E>add in class AbstractList<E>location - the index at which to insert the elementobject - the object to insert in this Vector
ArrayIndexOutOfBoundsException - when location < 0 || > size()addElement(E),
size()public boolean add(E object)
add in interface Collection<E>add in interface List<E>add in class AbstractList<E>object - the object to add to the Vector
public boolean addAll(int location,
Collection<? extends E> collection)
addAll in interface List<E>addAll in class AbstractList<E>location - the location to insert the objectscollection - the Collection of objects
ArrayIndexOutOfBoundsException - when location < 0 or location > size()public boolean addAll(Collection<? extends E> collection)
addAll in interface Collection<E>addAll in interface List<E>addAll in class AbstractCollection<E>collection - the Collection of objects
public void addElement(E object)
object - the object to add to the Vectorpublic int capacity()
ensureCapacity(int),
size()public void clear()
clear in interface Collection<E>clear in interface List<E>clear in class AbstractList<E>isEmpty(),
size()public Object clone()
clone in class ObjectCloneablepublic boolean contains(Object object)
contains in interface Collection<E>contains in interface List<E>contains in class AbstractCollection<E>object - the object to look for in this Vector
indexOf(Object),
indexOf(Object, int),
Object.equals(java.lang.Object)public boolean containsAll(Collection<?> collection)
containsAll in interface Collection<E>containsAll in interface List<E>containsAll in class AbstractCollection<E>collection - the Collection of objects
public void copyInto(Object[] elements)
elements - the Object array into which the elements
of this Vector are copiedclone()public E elementAt(int location)
location - the index of the element to return in this Vector
ArrayIndexOutOfBoundsException - when location < 0 || >= size()size()public Enumeration<E> elements()
elementAt(int),
Enumerationpublic void ensureCapacity(int minimumCapacity)
minimumCapacity - the minimum number of elements that this
vector will hold before growingcapacity()public boolean equals(Object object)
equals in interface Collection<E>equals in interface List<E>equals in class AbstractList<E>object - the object to compare with this object
hashCode()public E firstElement()
NoSuchElementException - when this vector is emptyelementAt(int),
lastElement(),
size()public E get(int location)
get in interface List<E>get in class AbstractList<E>location - the index of the element to return in this Vector
ArrayIndexOutOfBoundsException - when location < 0 || >= size()size()public int hashCode()
hashCode in interface Collection<E>hashCode in interface List<E>hashCode in class AbstractList<E>equals(java.lang.Object)public int indexOf(Object object)
indexOf in interface List<E>indexOf in class AbstractList<E>object - the object to find in this Vector
contains(java.lang.Object),
lastIndexOf(Object),
lastIndexOf(Object, int)public int indexOf(Object object,
int location)
object - the object to find in this Vectorlocation - the index at which to start searching
ArrayIndexOutOfBoundsException - when location < 0contains(java.lang.Object),
lastIndexOf(Object),
lastIndexOf(Object, int)public void insertElementAt(E object,
int location)
object - the object to insert in this Vectorlocation - the index at which to insert the element
ArrayIndexOutOfBoundsException - when location < 0 || > size()addElement(E),
size()public boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in interface List<E>isEmpty in class AbstractCollection<E>size()public E lastElement()
NoSuchElementException - when this vector is emptyelementAt(int),
firstElement(),
size()public int lastIndexOf(Object object)
lastIndexOf in interface List<E>lastIndexOf in class AbstractList<E>object - the object to find in this Vector
contains(java.lang.Object),
indexOf(Object),
indexOf(Object, int)public int lastIndexOf(Object object,
int location)
object - the object to find in this Vectorlocation - the index at which to start searching
ArrayIndexOutOfBoundsException - when location >= size()contains(java.lang.Object),
indexOf(Object),
indexOf(Object, int)public E remove(int location)
remove in interface List<E>remove in class AbstractList<E>location - the index of the element to remove
ArrayIndexOutOfBoundsException - when location < 0 || >= size()removeElement(java.lang.Object),
removeAllElements(),
size()public boolean remove(Object object)
remove in interface Collection<E>remove in interface List<E>remove in class AbstractCollection<E>object - the object to remove from this Vector
removeAllElements(),
removeElementAt(int),
size()public boolean removeAll(Collection<?> collection)
removeAll in interface Collection<E>removeAll in interface List<E>removeAll in class AbstractCollection<E>collection - the Collection of objects to remove
public void removeAllElements()
isEmpty(),
size()public boolean removeElement(Object object)
object - the object to remove from this Vector
removeAllElements(),
removeElementAt(int),
size()public void removeElementAt(int location)
location - the index of the element to remove
ArrayIndexOutOfBoundsException - when location < 0 || >= size()removeElement(java.lang.Object),
removeAllElements(),
size()protected void removeRange(int start,
int end)
removeRange in class AbstractList<E>start - the index at which to start removingend - the index one past the end of the range to remove
IndexOutOfBoundsException - when start < 0, start > end or end > size()public boolean retainAll(Collection<?> collection)
retainAll in interface Collection<E>retainAll in interface List<E>retainAll in class AbstractCollection<E>collection - the Collection of objects to retain
public E set(int location,
E object)
set in interface List<E>set in class AbstractList<E>location - the index at which to put the specified objectobject - the object to add to this Vector
ArrayIndexOutOfBoundsException - when location < 0 || >= size()size()public void setElementAt(E object,
int location)
object - the object to add to this Vectorlocation - the index at which to put the specified object
ArrayIndexOutOfBoundsException - when location < 0 || >= size()size()public void setSize(int length)
length - the new size of this Vectorsize()public int size()
size in interface Collection<E>size in interface List<E>size in class AbstractCollection<E>elementCount,
lastElement()public List<E> subList(int start,
int end)
subList in interface List<E>subList in class AbstractList<E>start - the index at which to start the sublistend - the index one past the end of the sublist
IndexOutOfBoundsException - when start < 0 or end > size()
IllegalArgumentException - when start > end
toArray
public Object[] toArray()
- Answers a new array containing all elements contained in this Vector.
- Specified by:
toArray in interface Collection<E>- Specified by:
toArray in interface List<E>- Overrides:
toArray in class AbstractCollection<E>
- Returns:
- an array of the elements from this Vector
toArray
public <T> T[] toArray(T[] contents)
- Answers 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.
- Specified by:
toArray in interface Collection<E>- Specified by:
toArray in interface List<E>- Overrides:
toArray in class AbstractCollection<E>
- 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
toString
public String toString()
- Answers the string representation of this Vector.
- Overrides:
toString in class AbstractCollection<E>
- Returns:
- the string representation of this Vector
- See Also:
elements()
trimToSize
public void trimToSize()
- Sets the capacity of this Vector to be the same as the size.
- See Also:
capacity(),
ensureCapacity(int),
size()
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
Final
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
Licensed Materials - Property of IBM
© Copyright IBM Corp. 2006, 2007 All Rights Reserved.