|
||||||||
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.
lib |
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 this Vector object. |
protected Object[] |
elementData
The array buffer into which the components of the vector are stored. |
Constructor Summary | |
---|---|
Vector()
Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero. |
|
Vector(int initialCapacity)
Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero. |
|
Vector(int initialCapacity,
int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity increment. |
Method Summary | |
---|---|
void |
add(int index,
Object element)
Inserts the specified element at the specified position in this Vector. |
boolean |
add(Object o)
Appends the specified element to the end of this Vector. |
int |
capacity()
Returns the current capacity of this vector. |
void |
clear()
Removes all of the elements from this Vector. |
Object |
clone()
Returns a clone of this vector. |
boolean |
contains(Object elem)
Tests if the specified object is a component in this vector. |
boolean |
equals(Object o)
Compares the specified Object with this Vector for equality. |
Object |
firstElement()
Returns the first component (the item at index 0) of this vector. |
Object |
get(int index)
Returns the element at the specified position in this Vector. |
int |
indexOf(Object elem)
Searches for the first occurrence 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. |
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. |
Object |
remove(int index)
Removes the element at the specified position in this Vector. |
boolean |
remove(Object o)
Removes the first occurrence of the specified element in this Vector. |
Object |
set(int index,
Object element)
Replaces the element at the specified position in this Vector with the specified element. |
void |
setSize(int newSize)
Sets the size of this vector. |
int |
size()
Returns the number of components in this vector. |
Object[] |
toArray()
Returns an array containing all of the elements in this Vector in the correct order. |
void |
trimToSize()
Trims the capacity of this vector to be the vector's current size. |
Methods inherited from class java.lang.Object |
---|
notifyAll, wait |
Field Detail |
---|
protected int capacityIncrement
vector
is automatically incremented when its size becomes greater than its capacity.
protected int elementCount
protected Object[] elementData
Constructor Detail |
---|
public Vector()
public Vector(int initialCapacity) throws IllegalArgumentException
initialCapacity
- the initial capacity of the vector.
IllegalArgumentException
public Vector(int initialCapacity, int capacityIncrement) throws IllegalArgumentException
initialCapacity
- the initial capacity of the vector.capacityIncrement
- the amount by which the capacity is increased when the vector overflows.
IllegalArgumentException
Method Detail |
---|
public void add(int index, Object element)
index
- index at which the specified element is to be inserted.element
- element to be inserted.public boolean add(Object o)
o
- element to be appended to this Vector.
public int capacity()
public void clear()
public Object clone()
clone
in class Object
Cloneable
public boolean contains(Object elem)
elem
- an object to look for
public boolean equals(Object o)
equals
in class Object
o
- the Object to be compared for equality with this Vector.
public Object firstElement()
public Object get(int index)
index
- index of element to return.
public int indexOf(Object elem)
elem
- an object.
public int indexOf(Object elem, int index)
elem
- an objectindex
- the non-negative index to start searching from.
public boolean isEmpty()
public Object lastElement()
public int lastIndexOf(Object elem)
elem
- an object
public int lastIndexOf(Object elem, int index)
elem
- the desired component.index
- the index to start searching from.
public Object remove(int index)
index
- the index of the element to removed.
public boolean remove(Object o)
o
- element to be removed from this Vector, if present.
public Object set(int index, Object element)
index
- index of element to replace.element
- element to be stored at the specified position.
public void setSize(int newSize)
null
items are added to the end of the vector.
If the new size is less than the current size, all components at index
newSize
and greater are discarded.
newSize
- the new size of this vector.public int size()
public Object[] toArray()
public void trimToSize()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |