Introduction
The Vector class implements a growable array (dynamic array). In the vector class, a component is stored at an integer index and it can be accessed by this index number like an Array. A Vector is synchronized and it contains many legacy methods that are not part of the collection framework. As of Java1.2, the Vector class has been retrofitted to implement a List.
Hierarchy of vector class
Constructor Summary
- Vector(): Creates an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.
- Vector(Collection<? extends E> c): Creates a vector containing the elements of the specified collection, in the order, they are returned by the collection's iterator.
- Vector(int initialCapacity): Creates an empty vector with the specified initial capacity and with its capacity increment equal to zero.
- Vector(int initialCapacity, int capacityIncrement): Creates an empty vector with the specified initial capacity and capacity increment.
Method Summary
Methods for Add elements to this vector: The following methods are used to add an element of the vector class.
| Return type | Method name | Description of functionality |
| boolean | add(E e) | Appends the specified element to the end of this Vector. |
| void | add(int index, E element) | Inserts the specified element at the specified position in this Vector. |
| boolean | addAll(Collection<? extends E> c) | Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator. |
| boolean | addAll(int index, Collection<? extends E> c) | Inserts all of the elements in the specified Collection into this Vector at the specified position. |
| void | addElement(E obj) | Adds the specified component to the end of this vector, increasing its size by one. |
| void | insertElementAt(E obj, int index) | Inserts the specified object as a component in this vector at the specified index. |
Methods for Size and capacity: The following methods are used to determine the capacity and size of the vector.
| Return type | Method name | Description of functionality |
| int | capacity() | Returns the current capacity 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. |
| void | setSize(int newSize) | Sets the size of this vector. |
| int | size() | Returns the number of components in this vector. |
| void | trimToSize() | Trims the capacity of this vector to be the vector's current size. |
Methods for Remove all elements from a vector: Used for removing all the elements of the vector.
| Return type | Method name | Description of functionality |
| void | clear() | Removes all of the elements from this Vector. |
Clone a vector: This method is used for making an object clone of the vector class.
| Return type | Method name | Description of functionality |
| Object | clone() | Returns a clone of this vector |
Methods for check contain a certain element: These methods are for checking whether elements are present or not.
| Return type | Method name | Description of functionality |
| boolean | contains(Object o) | Returns true if this vector contains the specified element. |
| boolean | containsAll(Collection<?> c) | Returns true if this Vector contains all of the elements in the specified Collection. |
Methods for Copy elements: This method is used to copy elements of a vector into an array.
| Return type | Method name | Description of functionality |
| void | copyInto(Object[] anArray) | Copies the components of this vector into the specified array. |
Methods for Get Enumeration from this vector: This method is for getting an enumeration object from a vector class.
| Return type | Method name | Description of functionality |
| Enumeration<E> | elements() | Returns an enumeration of the components of this vector. |
Methods for Compare two vectors: This method is used to compare the elements of two vector class objects.
| Return type | Method name | Description of functionality |
| boolean | equals(Object o) | Compares the specified Object with this Vector for equality. |
Methods for Get element from vector: Using are following methods we can get the elements of a vector object as needed.
| Return type | Method name | Description of functionality |
| E | elementAt(int index) | Returns the component at the specified index |
| E | firstElement() | Returns the first component (the item at index 0) of this vector. |
| E | get(int index) | Returns the element at the specified position in this Vector |
| E | lastElement() | Returns the last component of the vector. |
Methods for check is vector empty: This method is used to check whether a vector is empty or not.


Comments
Join the conversation! Your thoughts help the community grow.