Wednesday, 25 January 2017

Vector : RemoveElement


import java.util.Vector;

public class RemoveElement {

    public static void main(String[] args) {
        // TODO Auto-generated method stub


        Vector<String> v = new Vector<>();
        v.add("v1");
        v.add("v2");
        v.add("v3");
        v.add("v4");
       
        System.out.println("Vector v : "+v);
       
        Vector<String> v1 = new Vector<>();
        v1.add("a1");
        v1.addAll(v);
        v1.add("a3");
        v1.add("a4");

        System.out.println("Vector v : "+v1);
       
        System.out.println("removeElement('a2') : "+v1.removeElement("a2"));
        System.out.println("Vector v : "+v1);
        v1.removeElementAt(2);
        System.out.println("removeElementAt(2) : "+v1);
        v1.removeAllElements();
        System.out.println("removeAllElements() : "+v1);
       
       
    }
}

No comments:

Post a Comment