Dictionary क्लास एक एब्स्ट्रैक्ट क्लास है जो कुंजी/मान जोड़े को दर्शाती है और Map की तरह काम करती है और यह जावा में एक लिगेसी क्लास है। एक Dictionary क्लास में दो महत्वपूर्ण मेथड्स Dictionary.keys() और Dictionary.elements() होते हैं जिन्हें Enumeration द्वारा इटरेट किया जा सकता है। Dictionary क्लास के अन्य महत्वपूर्ण मेथड्स हैं isEmpty(), get(), remove() और size()।
सिंटैक्स
public abstract class Dictionary<K,V> extends Object
उदाहरण
import java.util.*;
public class DictionaryTest {
public static void main(String[] args) {
Dictionary<Integer, String> dic = new Hashtable<Integer, String>();
dic.put(1, "Adithya");
dic.put(2, "Jaidev");
dic.put(3, "Raja");
Enumeration<Integer> key = dic.keys();
while(key.hasMoreElements()) {
System.out.println(key.nextElement());
}
Enumeration<String> element = dic.elements();
while(element.hasMoreElements()) {
System.out.println(element.nextElement());
}
}
}
आउटपुट
3 2 1 Raja Jaidev Adithya