HashTable Enumeration elements() Method Example Program


Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.

Program

package com.candidjava;

import java.util.Hashtable;
import java.util.Enumeration;

/**
 * @author: Hari Haran
 * @discription: The elements() method is used to return an enumeration of the
 *               values in this hashtable.
 */

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

		Hashtable<Integer, String> ht = new Hashtable<Integer, String>();

		ht.put(1, "Anand");
		ht.put(2, "Hari Haran");
		ht.put(3, "Kamal");
		ht.put(4, "Karthikeyan");
		ht.put(5, "Mohan");
		ht.put(6, "Vinoth");
		ht.put(7, "Hari Haran");

		Enumeration e = ht.elements();

		System.out.println("Display result:");

		while (e.hasMoreElements()) {
			System.out.println(e.nextElement());
		}
	}
}

Output

Display result:
Hari Haran
Vinoth
Mohan
Karthikeyan
Kamal
Hari Haran
Anand

Explanation

public Enumeration<V> elements()
Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.
Specified by:
elements in class Dictionary<K,V>
Returns:
an enumeration of the values in this hashtable.


Related Post

Comments


©candidjava.com