10:29 pm - Monday March 27, 2017

Hash table example program enumeration of the values using enumaration() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Hash table Program is used for enumaration of the values using enumaration() method.

Example Program


import java.util.Enumeration;

import java.util.Hashtable;

public class HashTableEnum {

public static void main(String[] args) {

// create two has table

Hashtable htable = new Hashtable();

// put value into table

htable.put(1, "Dog");

htable.put(2, "Cat");

htable.put(3, "Cow");

htable.put(4, "Donkey");

// create enumeration

Enumeration e = htable.elements();

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

// display search results

while (e.hasMoreElements()) {

System.out.println(e.nextElement());

}

}

}

 

Output

Display result :

Donkey

Cow

Cat

Dog

 

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.

 

See Also:

Enumeration, keys(), values(), Map

BACK

Filed in: Z-A All Java Codes

Comments are closed.