Vector class setElementAt(E obj, int index) method example
Sets the component at the specified index of this vector to be the specified object.
Vector class setElementAt(E obj, int index) method example. This example shows you how to use setElementAt(E obj, int index) method.This method Sets the component at the specified index of this vector to be the specified object.
Here is the code:-
/*
* @Program that Sets the component at the specified index of this vector to be
the specified object.
* SetElementAt.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class SetElementAt {
public static void main(String[] args) {
Vector v = new Vector();
v.add("Rose");
v.add("India");
v.add("Rohini");
Enumeration e = v.elements();
System.out.print("Elements of the vector is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
//Sets the component at the specified index of this vector to be the specified
//object.
v.setElementAt(".NET", 2);
Enumeration e1 = v.elements();
System.out.println();
System.out.print("Vector after Setting the component at the specified index: ");
while (e1.hasMoreElements()) {
System.out.print(e1.nextElement() + "\t");
}
}
}
|
Output of the program:-
Elements of the vector is : Rose India Rohini
Vector after Setting the component at the specified index: Rose India .NET |
|