The Vector class also provides the resizable-array implementations of the List interface (similar to the ArrayList class). Some of the Vector methods are:
Add Elements to Vector
- add(element) - adds an element to vectors
- add(index, element) - adds an element to the specified position
- addAll(vector) - adds all elements of a vector to another vector
For example,
Output
Access Vector Elements
- get(index) - returns an element specified by the index
- iterator() - returns an iterator object to sequentially access vector elements
For example,
Output
Remove Vector Elements
- remove(index) - removes an element from specified position
- removeAll() - removes all the elements
- clear() - removes all elements. It is more efficient than removeAll()
For example,
Output