Vector class insertElementAt(E obj, int index)method example
Inserts the specified object as a component in this vector at the specified index.
Vector class insertElementAt(E obj, int index)method example. This example shows you how to use insertElementAt(E obj, int index)method.This method Inserts the specified object as a component in this vector at the specified index.
Here is the code:-
/*
* @Program that Inserts the specified object as a component in this vector at
the specified index.
* InsertElementAt.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class InsertElementAt {
public static void main(String[] args) {
//Creating vector
Vector v = new Vector();
//Adding element to the vector
v.add("Rose");
v.add("India");
v.add("Rohini");
v.add("Girish");
//Creating Enumeration Interface
Enumeration e = v.elements();
System.out.print("Vector before inserting is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
System.out.println();
//Inserts the specified object as a component in this vector at the specified
//index.
v.insertElementAt("Tewari", 4);
Enumeration e1 = v.elements();
System.out.print("Vector after inserting is : ");
while (e1.hasMoreElements()) {
System.out.print(e1.nextElement() + "\t");
}
}
} |
Output of the program:-
Vector before inserting is : Rose India Rohini Girish
Vector after inserting is : Rose India Rohini Girish Tewari |
|