Thursday 14 March 2013

java.util Vector


java.util
Vector

Declaration
public class Vector
java.lang.Object
|
+--java.util.Vector
Direct Known Subclasses: Stack
Description
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.
Since: JDK1.0, CLDC 1.0
Member Summary
Fields
protected int capacityIncrement
protected int elementCount
protected
java.lang.Object
elementData
Constructors
Vector()
Vector(int initialCapacity)
Vector(int initialCapacity, int capacityIncrement)
Methods
void addElement(java.lang.Object obj)
int capacity()
boolean contains(java.lang.Object elem)
void copyInto(java.lang.Object anArray)
java.lang.Object elementAt(int index)
Enumeration elements()
void ensureCapacity(int minCapacity)
java.lang.Object firstElement()
int indexOf(java.lang.Object elem)
int indexOf(java.lang.Object elem, int index)
void insertElementAt(java.lang.Object obj, int index)



elementData

Fields
elementData
Declaration:
protected java.lang.Object[] elementData
Description:
The array buffer into which the components of the vector are stored. The capacity of the vector is the length
of this array buffer.
Since: JDK1.0
elementCount
Declaration:
protected int elementCount
Description:
The number of valid components in the vector.
Since: JDK1.0
capacityIncrement
Declaration:
protected int capacityIncrement
boolean isEmpty()
java.lang.Object lastElement()
int lastIndexOf(java.lang.Object elem)
int lastIndexOf(java.lang.Object elem, int index)
void removeAllElements()
boolean removeElement(java.lang.Object obj)
void removeElementAt(int index)
void setElementAt(java.lang.Object obj, int index)
void setSize(int newSize)
int size()
java.lang.String toString()
void trimToSize()


Methods inherited from class Object
equals(Object), getClass(), hashCode(), notify(), notifyAll(), wait(), wait(), wait()



Fields
elementData
Declaration:
protected java.lang.Object[] elementData
Description:
The array buffer into which the components of the vector are stored. The capacity of the vector is the length
of this array buffer.
Since: JDK1.0
elementCount
Declaration:
protected int elementCount
Description:
The number of valid components in the vector.
Since: JDK1.0
capacityIncrement
Declaration:
protected int capacityIncrement


Description:
The amount by which the capacity of the vector is automatically incremented when its size becomes greater
than its capacity. If the capacity increment is 0, the capacity of the vector is doubled each time it needs to
grow.
Since: JDK1.0
Constructors
Vector(int, int)
Declaration:
public Vector(int initialCapacity, int capacityIncrement)
Description:
Constructs an empty vector with the specified initial capacity and capacity increment.
Parameters:
initialCapacity - the initial capacity of the vector.
capacityIncrement - the amount by which the capacity is increased when the vector overflows.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative
Vector(int)
Declaration:
public Vector(int initialCapacity)
Description:
Constructs an empty vector with the specified initial capacity.
Parameters:
initialCapacity - the initial capacity of the vector.
Since: JDK1.0
Vector()
Declaration:
public Vector()
Description:
Constructs an empty vector.
Since: JDK1.0


Methods
copyInto(Object[])
Declaration:
public void copyInto(java.lang.Object[] anArray)


trimToSize()

Description:
Copies the components of this vector into the specified array. The array must be big enough to hold all the
objects in this vector.
Parameters:
anArray - the array into which the components get copied.
Since: JDK1.0
trimToSize()
Declaration:
public void trimToSize()
Description:
Trims the capacity of this vector to be the vector’s current size. An application can use this operation to
minimize the storage of a vector.
Since: JDK1.0
ensureCapacity(int)
Declaration:
public void ensureCapacity(int minCapacity)
Description:
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.
Parameters:
minCapacity - the desired minimum capacity.
Since: JDK1.0
setSize(int)
Declaration:
public void setSize(int newSize)
Description:
Sets the size of this vector. If the new size is greater than the current size, new 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.
Parameters:
newSize - the new size of this vector.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if new size is negative.
Since: JDK1.0
capacity()
Declaration:
public int capacity()
Description:
Returns the current capacity of this vector.


Returns: the current capacity of this vector.
Since: JDK1.0
size()
Declaration:
public int size()
Description:
Returns the number of components in this vector.
Returns: the number of components in this vector.
Since: JDK1.0
isEmpty()
Declaration:
public boolean isEmpty()
Description:
Tests if this vector has no components.
Returns: true if this vector has no components; false otherwise.
Since: JDK1.0
elements()
Declaration:
public java.util.Enumeration elements()
Description:
Returns an enumeration of the components of this vector.
Returns: an enumeration of the components of this vector.
Since: JDK1.0
See Also: Enumeration
contains(Object)
Declaration:
public boolean contains(java.lang.Object elem)
Description:
Tests if the specified object is a component in this vector.
Parameters:
elem - an object.
Returns: true if the specified object is a component in this vector; false otherwise.
Since: JDK1.0
indexOf(Object)
Declaration:
public int indexOf(java.lang.Object elem)


indexOf(Object, int)

Description:
Searches for the first occurence of the given argument, testing for equality using the equals method.
Parameters:
elem - an object.
Returns: the index of the first occurrence of the argument in this vector; returns -1 if the object is not
found.
Since: JDK1.0
See Also: java.lang.Object.equals(Object)
indexOf(Object, int)
Declaration:
public int indexOf(java.lang.Object elem, int index)
Description:
Searches for the first occurence of the given argument, beginning the search at index, and testing for
equality using the equals method.
Parameters:
elem - an object.
index - the index to start searching from.
Returns: the index of the first occurrence of the object argument in this vector at position index or later
in the vector; returns -1 if the object is not found.
Since: JDK1.0
See Also: java.lang.Object.equals(Object)
lastIndexOf(Object)
Declaration:
public int lastIndexOf(java.lang.Object elem)
Description:
Returns the index of the last occurrence of the specified object in this vector.
Parameters:
elem - the desired component.
Returns: the index of the last occurrence of the specified object in this vector; returns -1 if the object is
not found.
Since: JDK1.0
lastIndexOf(Object, int)
Declaration:
public int lastIndexOf(java.lang.Object elem, int index)
Description:
Searches backwards for the specified object, starting from the specified index, and returns an index to it.
Parameters:
elem - the desired component.
index - the index to start searching from.


Returns: the index of the last occurrence of the specified object in this vector at position less than index
in the vector; -1 if the object is not found.
Throws:
java.lang.IndexOutOfBoundsException - if index is greater than or equal to the current
size of this vector.
Since: JDK1.0
elementAt(int)
Declaration:
public java.lang.Object elementAt(int index)
Description:
Returns the component at the specified index.
Parameters:
index - an index into this vector.
Returns: the component at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.
Since: JDK1.0
firstElement()
Declaration:
public java.lang.Object firstElement()
Description:
Returns the first component of this vector.
Returns: the first component of this vector.
Throws:
NoSuchElementException - if this vector has no components.
Since: JDK1.0
lastElement()
Declaration:
public java.lang.Object lastElement()
Description:
Returns the last component of the vector.
Returns: the last component of the vector, i.e., the component at index size() - 1.
Throws:
NoSuchElementException - if this vector is empty.
Since: JDK1.0
setElementAt(Object, int)
Declaration:
public void setElementAt(java.lang.Object obj, int index)

removeElementAt(int)

Description:
Sets the component at the specified index of this vector to be the specified object. The previous
component at that position is discarded.
The index must be a value greater than or equal to 0 and less than the current size of the vector.
Parameters:
obj - what the component is to be set to.
index - the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
Since: JDK1.0
See Also: size()
removeElementAt(int)
Declaration:
public void removeElementAt(int index)
Description:
Deletes the component at the specified index. Each component in this vector with an index greater or equal
to the specified index is shifted downward to have an index one smaller than the value it had previously.
The index must be a value greater than or equal to 0 and less than the current size of the vector.
Parameters:
index - the index of the object to remove.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
Since: JDK1.0
See Also: size()
insertElementAt(Object, int)
Declaration:
public void insertElementAt(java.lang.Object obj, int index)
Description:
Inserts the specified object as a component in this vector at the specified index. Each component in this
vector with an index greater or equal to the specified index is shifted upward to have an index one greater
than the value it had previously.
The index must be a value greater than or equal to 0 and less than or equal to the current size of the vector.
Parameters:
obj - the component to insert.
index - where to insert the new component.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
Since: JDK1.0
See Also: size()


addElement(Object)
Declaration:
public void addElement(java.lang.Object obj)
Description:
Adds the specified component to the end of this vector, increasing its size by one. The capacity of this
vector is increased if its size becomes greater than its capacity.
Parameters:
obj - the component to be added.
Since: JDK1.0
removeElement(Object)
Declaration:
public boolean removeElement(java.lang.Object obj)
Description:
Removes the first occurrence of the argument from this vector. If the object is found in this vector, each
component in the vector with an index greater or equal to the object’s index is shifted downward to have an
index one smaller than the value it had previously.
Parameters:
obj - the component to be removed.
Returns: true if the argument was a component of this vector; false otherwise.
Since: JDK1.0
removeAllElements()
Declaration:
public void removeAllElements()
Description:
Removes all components from this vector and sets its size to zero.
Since: JDK1.0
toString()
Declaration:
public java.lang.String toString()
Description:
Returns a string representation of this vector.
Overrides: toString in class Object
Returns: a string representation of this vector.
Since: JDK1.0










No comments:

Post a Comment