Dictionary class elements() method example
Dictionary class elements() method example. This example shows you how to use elements()method.This method Returns an enumeration of the values in this dictionary.
Here is the code:-
/**
* @Program Returns an enumeration of the values in this dictionary.
* ElementsDictionary.java
* Author:-RoseIndia Team
* Date:-21-May-2008
*/
import java.util.*;
public class ElementsDictionary {
public static void main(String[] args) {
// Creating a hashtable object:
Dictionary d = new Hashtable();
// Adding elements: i.e (key,value):
System.out.println("Current value at \"1\" is "
+ d.put("4", "Girish"));
// Adding a key that is already present.
System.out.print("The current value at \"4\" is "
+ d.put("4"," "+"Tewari"));
//the Enumeration interface generates a series of elements, one at a
//time
for (Enumeration e = d.elements(); e.hasMoreElements();)
System.out.println(e.nextElement());
}
} |
Output of the program:-
Current value at "1" is null
The current value at "4" is Girish Tewari |
|