Java Vector.addElement(E obj)

Syntax

Vector.addElement(E obj) has the following syntax.

public void addElement(E obj)

Example

In the following code shows how to use Vector.addElement(E obj) method.


/*from   ww w  .  j  a  va 2 s .c  om*/

import java.util.Vector;

public class Main {
   public static void main(String[] args) {
           
      Vector<Integer>  vec = new Vector<Integer> (4);

      
      vec.add(4);
      vec.add(3);
      vec.add(2);
      vec.add(1);

      System.out.println(vec);
      
      // add new element
      vec.addElement(12);
      
      System.out.println(vec);
   }    
}

The code above generates the following result.