Monday, 25 May 2015

How to replace element of vector

 We can replace any specific index element by other element using set(int index,element) method.

import java.util.Vector;

public class ReplaceElement {
 public static void main(String[] args) {
         Vector<String> vector = new Vector<String>();
         //add element in vector
         // print vector
         System.out.println("Before replace Vector is = "+vector);
          * Replaces the element at the specified
          * position in this Vector with the
          *  specified element.
         System.out.println("After Replace element vector is = "+vector);



Before replace Vector is = [cricket, hockey, football, tennish]

After Replace element vector is = [cricket, Apple, football, tennish]

No comments:

Post a Comment