|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.Vector
public class Vector
The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement. The capacity is always at least as large as the vector size; it is usually larger because as components are added to the vector, the vector's storage increases in chunks the size of capacityIncrement. An application can increase the capacity of a vector before inserting a large number of components; this reduces the amount of incremental reallocation.
| Field Summary | |
|---|---|
protected int |
capacityIncrement
The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. |
protected int |
elementCount
The number of valid components in the vector. |
protected Object[] |
elementData
The array buffer into which the components of the vector are stored. |
| Constructor Summary | |
|---|---|
Vector()
Constructs an empty vector. |
|
Vector(int initialCapacity)
Constructs an empty vector with the specified initial capacity. |
|
Vector(int initialCapacity,
int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity increment. |
|
| Method Summary | |
|---|---|
void |
addElement(Object obj)
Adds the specified component to the end of this vector, increasing its size by one. |
int |
capacity()
Returns the current capacity of this vector. |
boolean |
contains(Object elem)
Tests if the specified object is a component in this vector. |
void |
copyInto(Object[] anArray)
Copies the components of this vector into the specified array. |
Object |
elementAt(int index)
Returns the component at the specified index. |
Enumeration |
elements()
Returns an enumeration of the components of this vector. |
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. |
Object |
firstElement()
Returns the first component of this vector. |
int |
indexOf(Object elem)
Searches for the first occurence of the given argument, testing for equality using the equals method. |
int |
indexOf(Object elem,
int index)
Searches for the first occurence of the given argument, beginning the search at index, and testing for equality using the equals method. |
void |
insertElementAt(Object obj,
int index)
Inserts the specified object as a component in this vector at the specified index. |
boolean |
isEmpty()
Tests if this vector has no components. |
Object |
lastElement()
Returns the last component of the vector. |
int |
lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in this vector. |
int |
lastIndexOf(Object elem,
int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it. |
void |
removeAllElements()
Removes all components from this vector and sets its size to zero. |
boolean |
removeElement(Object obj)
Removes the first occurrence of the argument from this vector. |
void |
removeElementAt(int index)
Deletes the component at the specified index. |
void |
setElementAt(Object obj,
int index)
Sets the component at the specified index of this vector to be the specified object. |
void |
setSize(int newSize)
Sets the size of this vector. |
int |
size()
Returns the number of components in this vector. |
String |
toString()
Returns a string representation of this vector. |
void |
trimToSize()
Trims the capacity of this vector to be the vector's current size. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected int capacityIncrement
protected int elementCount
protected Object[] elementData
| Constructor Detail |
|---|
public Vector()
public Vector(int initialCapacity)
public Vector(int initialCapacity,
int capacityIncrement)
| Method Detail |
|---|
public void addElement(Object obj)
public int capacity()
public boolean contains(Object elem)
public void copyInto(Object[] anArray)
public Object elementAt(int index)
public Enumeration elements()
public void ensureCapacity(int minCapacity)
public Object firstElement()
public int indexOf(Object elem)
public int indexOf(Object elem,
int index)
public void insertElementAt(Object obj,
int index)
public boolean isEmpty()
public Object lastElement()
public int lastIndexOf(Object elem)
public int lastIndexOf(Object elem,
int index)
public void removeAllElements()
public boolean removeElement(Object obj)
obj - the component to be removed.
true if the argument was a component of this vector; false otherwise.public void removeElementAt(int index)
public void setElementAt(Object obj,
int index)
public void setSize(int newSize)
public int size()
public String toString()
toString in class Objectpublic void trimToSize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||