public class Vector
extends java.lang.Object
Here is an example showing a vector being used:
... Vector vec = new Vector(); vec.addElement(obj1); vec.addElement(obj2); ... vec.insertElementAt(obj3, 3); vec.removeElementAt(2); if (vec.size() > 5) ...This Vector class does not support Generics; use the ArrayList class instead.
Modifier and Type | Field and Description |
---|---|
protected int |
count |
java.lang.Object[] |
items
This member is public for fast access.
|
Constructor and Description |
---|
Vector()
Constructs an empty vector.
|
Vector(int size)
Constructs an empty vector with a given initial size, which is
the initial size of the vector's internal object array.
|
Vector(java.lang.Object[] startingWith)
Constructs a vector starting with the given elements.
|
Modifier and Type | Method and Description |
---|---|
void |
addElement(java.lang.Object obj)
Adds an object to the end of the vector.
|
void |
addElements(java.lang.Object[] objects)
Adds an array of objects at the end of the vector.
|
void |
addElementsNotNull(java.lang.Object[] objects)
Adds an array of objects at the end of the vector
(null objects are skipped).
|
boolean |
contains(java.lang.Object o)
Returns true if this vector contains the specified element.
|
void |
copyInto(java.lang.Object[] out)
Copies the items of this vector into the given array, which must have at least the current size of this vector.
|
java.lang.String |
dump()
Dumps the contents of this vector and returns a string of it.
|
java.lang.Object |
elementAt(int i) |
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.
|
int |
indexOf(java.lang.Object elem)
Finds the index of the given object.
|
int |
indexOf(java.lang.Object obj,
int startIndex)
Finds the index of the given object.
|
void |
insertElementAt(java.lang.Object obj,
int index)
Inserts the object at the given index.
|
boolean |
isEmpty()
Returns if this Vector is empty.
|
java.lang.Object |
peek()
Returns the last object, without removing it.
|
java.lang.Object |
peek(int n)
Returns the n-last object, without removing it.
|
java.lang.Object |
peek(java.lang.Object def)
Returns the last object, without removing it, or the given default value.
|
java.lang.Object |
pop()
Returns the last object, removing it.
|
void |
pop(int n)
Pops n last elements from the stack.
|
java.lang.Object |
pop(java.lang.Object def)
Returns the last object, removing it, or the given default value
|
void |
push(java.lang.Object obj)
Pushes an object.
|
void |
qsort()
Sorts the elements of this Vector.
|
void |
qsort(boolean ascending)
Sorts the elements of this Vector, in the given order.
|
void |
qsort(int sortType)
Sorts the elements of this Vector, with the given sort type.
|
void |
qsort(int sortType,
boolean ascending)
Sorts the elements of this Vector, with the given sort type and order.
|
void |
removeAllElements()
Clears all elements in this vector and sets the count to 0.
|
boolean |
removeElement(java.lang.Object obj)
Deletes the object.
|
void |
removeElementAt(int index)
Deletes the object reference at the given index.
|
void |
reverse()
Reverses the order of the elements in this vector.
In a vector with n elements, the element of index 0 is moved to the index n-1, the element of index 1 is moved to the index n-2, and so on. |
void |
setSize(int newSize)
Sets the size of this vector.
|
int |
size()
Returns the number of objects in the vector.
|
java.lang.Object[] |
toObjectArray()
Converts the vector to an array of objects.
|
java.lang.String |
toString()
Returns the items of this vector separated by comma
|
java.lang.String |
toString(java.lang.String separator)
Returns the items of this vector separated by the given string.
|
public java.lang.Object[] items
protected int count
public Vector()
public Vector(int size)
public Vector(java.lang.Object[] startingWith)
startingWith
- public java.lang.Object[] toObjectArray()
public void push(java.lang.Object obj)
public java.lang.Object pop() throws ElementNotFoundException
ElementNotFoundException
- When the stack is empty.public java.lang.Object peek() throws ElementNotFoundException
ElementNotFoundException
- When the stack is empty.public java.lang.Object peek(int n) throws ElementNotFoundException
peek(0)
is the same of peek()
.n
- How many elements to get from the top; must be a positive number.ElementNotFoundException
- When the stack is empty.public void pop(int n)
public java.lang.Object pop(java.lang.Object def)
public java.lang.Object peek(java.lang.Object def)
public boolean isEmpty()
public int size()
public void setSize(int newSize) throws java.lang.ArrayIndexOutOfBoundsException
newSize
- the new size of this vectorjava.lang.ArrayIndexOutOfBoundsException
- if the new size is negativepublic int indexOf(java.lang.Object elem)
public int indexOf(java.lang.Object obj, int startIndex)
public void removeElementAt(int index)
public void insertElementAt(java.lang.Object obj, int index)
public void addElement(java.lang.Object obj)
public void addElements(java.lang.Object[] objects)
objects
- array with the objects to be added to the vector.public void addElementsNotNull(java.lang.Object[] objects)
objects
- array with the objects to be added to the vector.public boolean removeElement(java.lang.Object obj)
public void removeAllElements()
null
,
so, if you had directly assigned an array to this vector, all items inside it will be nulled.public void qsort()
public void qsort(int sortType)
public void qsort(boolean ascending)
public void qsort(int sortType, boolean ascending)
public java.lang.String dump()
public void copyInto(java.lang.Object[] out)
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacitypublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String separator)
public boolean contains(java.lang.Object o)
o
- element whose presence in this vector is to be testedpublic void reverse()
public java.lang.Object elementAt(int i)