Vector elements() in Java

elements(): This method is available in java.util.Vector class of Java.

Syntax:

Enumeration<K> java.util.Vector.elements()

This method returns an enumeration of the components of this vector. The returned Enumeration object will generate all items in this vector.

Parameters: NA

Returns: an enumeration of the components of this vector.

Exceptions: NA

Approach

Java

import java.util.Enumeration;
import java.util.Vector;

public class Vectorelements {
    public static void main(String[] args) {

        Vector<String> vector = new Vector<>();

        vector.add("Hello");
        vector.add("Java");
        vector.add("C++");
        vector.add("Program");

        Enumeration<String> enumeration = vector.elements();

        while (enumeration.hasMoreElements()) {
            System.out.print(enumeration.nextElement() + " ");

        }

    }
}

Output:

Hello Java C++ Program 

No comments:

Post a Comment