Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorInsertElementAtExample3 { public static void main(String arg[]) { //Create an empty vector Vector < String > colors = new Vector < String > (); //Add elements in the vector colors.add("White"); colors.add("Green"); colors.add("Black"); //Print the elements of this vector System.out.println("Color elements in vector: " +colors); //Insert the element at 2nd position colors.insertElementAt("Red", 12); System.out.println("Element in vector after insertion = "+colors); } }
Output