Wednesday 10 December 2014

Java : Collection Framework : Vector (Enumeration)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=tY4fje5y-dQ&list=UUhwKlOVR041tngjerWxVccw

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

/*
 *  Example of elements() method. 
 */
public class VectorExample
{
    public static void main(String[] args)
    {
        Vector<Integer> vector = new Vector<Integer>();

        vector.add(10);
        vector.add(20);
        vector.add(30);
        vector.add(40);

        System.out.println("vector  : " + vector + "\n");

        /*
         * Returns an enumeration of the components 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<Integer> enumeration = vector.elements();

        /*
         * Tests if this enumeration contains more elements.
         */
        while (enumeration.hasMoreElements())
        {
            /*
             * Returns the next element of this enumeration if this enumeration
             * object has at least one more element to provide.
             */
            Integer value = enumeration.nextElement();
            System.out.println(value);

        }

    }
}

Output
vector  : [10, 20, 30, 40]

10
20
30
40


To Download VectorDemoEnumeration Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoEnumeration.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment