Vector are array list with extended properties which follow the dynamic and
automatic addition of data at run-time. Unlike array, Vector can grow and
shrink as needed to accommodate its size adding and removing items even after
Vector has been created. The
implements dynamic array of objects. The Component in vector class can be
accessed by integer index. Each vector tries to maintain its storage size
capacity and a
capacity Increment. The
of vector is always least as of its size and usually larger because
components are added to the vector at run-time. The vector's storage get
increase in chunks as the size of
capacity Increment. An
application increase the size of a vector before inserting a large number of
components that is used to reduce the amount of increment in reallocation. Vectors
can be easily used.. It implement the Enumeration interface which makes
the contents of a Vector traversed
Vector instances are like linked-lists that can grow dynamically. Once it reaches the maximum limit, resources are allocated dynamically and increases its size further.
How to declare Vector
The given below Syntax is used to declare an empty vector so that the size of internal data array has 10 and its standard storage capacity has zero.
The given Syntax is used to construct an empty vector specified by initial capacity.
vector(int initial capacity)
The below Syntax Creates an empty vector with the specified initial capacity and capacity increment.
vector(int initial capacity,int capacity increment)
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( ) - Return the current capacity of this vector
void clear( )- Removes all of the elements from this Vector.
void setsize(int new size )-Set the new size of Vector.
int size( )-Return the number of Component in Vector.
Vector trim to size( )- Trim the Capacity of Vector to vector's current size.
public int lastindexof(obj abc)-Returns the occurrence of last index of of the specified object in this vector.
Output of above code-
Maximum Element of java Vector is :900
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial