Hashtable elements Example


Hashtable class elements method example.Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially
syntax -public Enumeration elements()

Here is the code

/**
 * @ # Elements.java
 * A class repersenting use to elements method 
 * of HashMap class in java.util package
 * version 19 May 2008
 * author Rose India 
 */
import java.util.*;

public class Elements {

    public static void main(String args[]) {
        Hashtable table = new Hashtable();

        //Put value into the table
        table.put(1"A");
        table.put(2"B");
        table.put(3"C");
        table.put(4"D");

        System.out.println("table :" + table +
                "\nelements of table ...");

        Enumeration e = table.elements();
        while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
        }
    }
}

Output
 table :{4=D, 3=C, 2=B, 1=A}
elements of table ...
D
C
B
A

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US