The Java Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to values.Following are the important points about Dictionary −
In this class every key and every value is an object.
In his class object every key is associated with at most one value.
Following is the declaration for java.util.Dictionary class −
public abstract class Dictionary<K,V> extends ObjectClass constructors Sr.No. Constructor & Description 1
Dictionary()
This is the single constructor.
Class methods Methods inheritedThis class inherits methods from the following classes −
The following example shows the usage of Java Dictionary put(K,V) method. We're creating a dictionary instance using Hashtable object of Integer, Integer. Then we've added few elements to it using put(K,V) method. An enumeration is retrieved using elements() method and enumeration is then iterated to print the elements of the dictionary.
package com.tutorialspoint; import java.util.Enumeration; import java.util.Dictionary; import java.util.Hashtable; public class DictionaryDemo { public static void main(String[] args) { // create a new hashtable Dictionary<Integer, Integer> dictionary = new Hashtable<>(); // add 2 elements dictionary.put(1, 1); dictionary.put(2, 2); Enumeration<Integer> enumeration = dictionary.elements(); while(enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); } } }
Let us compile and run the above program, this will produce the following result −
2 1
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4