Vector Class in Java

Vector is a concrete class in Collection Framework. It is a dynamic representation of array and is synchronized. Since the vector is synchronized so it is a better choice for thread-safe operation. Synchronization is a process through which an object can be locked for a given thread and other thread cannot use that object when it is locked.


import java.util.Vector;

public class MyVector {
    public static void main(String args[])
    Vector vector=new Vector();     //creating object of Vector class
    vector.add("one");          //add method is use to add a value (can be object, String , integer)
    System.out.println(vector);     // prints the complete vector

    for(int k=0;k<vector.size();k++)    // prints value one by one

    System.out.println("Accessing particular index from vector\t"+vector.get(1));   //in Vector count starts from 0(zero)