• Java Data Structures Tutorial

Adding elements to a Vector



The Vector class provides addElement() method it accepts an object and adds the specified object/element to the current Vector.

You can add an element to a Vector object using the addElement() method by passing the element/object that is to be added as a parameter to this method.

vect.addElement("Java");

Example

import java.util.Vector;
public class CreatingVector {
   public static void main(String args[]) {
      Vector vect = new Vector();
      vect.addElement("Java");
      vect.addElement("JavaFX");
      vect.addElement("HBase");
      vect.addElement("Neo4j");
      vect.addElement("Apache Flume");
      System.out.println(vect);	   
   }
}

Output

[Java, JavaFX, HBase, Neo4j, Apache Flume]
Advertisements