share

Monday, 25 May 2015

How To Remove Element of Vector

import java.util.Vector;

public class RemoveElement {

    public static void main(String[] args) {
      
        Vector<String> vector = new Vector<String>();
        //add element in vector
        vector.add("cricket");
        vector.add("hockey");
        vector.add("football");
        vector.add("tennish");
      
        // print vector
        System.out.println("Vector = "+vector);
      
      
        /*
         * Removes the element at the specified position
         * in this Vector. Shifts any subsequent elements
         * to the left (subtracts one from their indices).
         * Returns the element that was removed from the
         *  Vector.
         */
        vector.remove(1);
      
        System.out.println("After remove element vector is = "+vector);
               
            }
     
}

Output:

Vector = [cricket, hockey, football, tennish]

After remove element vector is = [cricket, football, tennish]


No comments:

Post a Comment