Vector in Java

 Vector:

  • Vector is the implementation class of the List interface which is also used to store groups of individual objects where duplicate values are allowed.
  • Vector is exactly similar to ArrayList but ArrayList is not a synchronized class whereas Vector is a synchronized class.
  • Vector is also called legacy class because it is available from Java 1.0 version.

creation of Vector:

Vector<E> v = new Vector<E>(); 
Vector<E> v = new Vector<E>(int capacity);
Vector<E> v = new Vector<E>(Collection obj);

Methods:

  • we can also use legacy methods like addElement(), removeElement(), setElementAt()...
Example:

vector example
Output:


  • difference ArrayList Vs LinkedList Vs Vector Vs Stack.

Vector Vs Stack






You May Also Like

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.