Java Vector.elements() Method

 Posted On  | Yashwant Chavan 

In this tutorial, you will learn about Java Vector.elements() Method. This method returns an enumeration of the elements of this Vector.


Returns an enumeration of the elements of this vector. The returned Enumeration object will generate all items in this vector. The first item generated is the item at index 0, then the item at index 1, and so on.

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


returns an enumeration of the elements of this vector

Java example to get Vector elements

  • Create Vector instance using new Vector().
  • Add some elements in the Vector.
  • elements() method is used to get the enumeration of the Vector elements. Enumerate each Vector element and print the value.

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

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

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

        Enumeration < String > enumeration = colors.elements();
        while (enumeration.hasMoreElements()) {
            System.out.println("Color:- " + enumeration.nextElement());



Color:- Red
Color:- Green
Color:- Blue
Color:- Pink

© 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0283 seconds.