Vector class Java is the general purpose Data Structure used very often by the Programmers. Vector, though belongs to legacy classes (DS of JDK 1.0), it can use the methods of List interface as Vector implements List from JDK 1.2. In this way, Vector became part of collections framework.
All Java Vector class methods are synchronized and thus best suitable to use in multithreaded environment.
Following is a simple example on Vector class Java and for indepth knowledge 5 links are also given.
public class PrintElements
public static void main(String args)
Vector vect1 = new Vector();
Enumeration e = vect1.elements();
Output Screenshot of Example on Vector class Java
Vector object vect1 is created and added elements with add() method. The elements() method of Vector returns an object of Enumeration interface with all the elements of vect1. The method hasMoreElements() of Vector iterates all the elements of the Vector. The nextElement() method returns each element.
This is simple example and explanation and for more indepth on Vector class with all operations on elements read these 5 examples:
1. Vector Methods
2. Vector Generics
3. Vector Retrieval
4. Vector Play With
5. Vector vs ArrayList