Vector class set(int index, E element) method example
Replaces the element at the specified position in this Vector with the specified element.
Vector class set(int index, E element) method example. This example shows you how to use set(int index, E element) method.This method Replaces the element at the specified position in this Vector with the specified element.
Here is the code:-
/*
* @Program that Replaces the element at the specified position in this Vector
with the specified element.
* Set.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class Set {
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");
}
//Replaces the element at the specified position in this Vector with the
//specified element.
v.set(2, ".NET");
Enumeration e1 = v.elements();
System.out.println();
System.out.print("Vector after Replacing the element at the specified position is: ");
while (e1.hasMoreElements()) {
System.out.print(e1.nextElement() + "\t");
}
}
}
|
Output of the program:-
Elements of the vector is : Rose India Rohini
Vector after Replacing the element at the specified position is: Rose India .NET |
|