Monday, 25 May 2015

How to remove all element from vector

We can remove all element of vector using clear() method . clear() removes all element from the list and return empty list.

import java.util.Vector;

public class RemoveAll {
    public static void main(String[] args) {
        Vector<String> vector = new Vector<String>();
        //add element in vector
        // print vector
        System.out.println("Vector is = "+vector);
         * Removes all of the elements from this
         * Vector. The Vector will be empty after
         *  this call returns (unless it throws an
         *   exception).
        System.out.println("Vector After Clear is = "+vector);



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

Vector After Clear is = []

No comments:

Post a Comment