Java中Dictionary类的重要性?
甲字典 类是一个 抽象类,它表示一个键/值对和操作类似于图 ,这是一个传统的类中的Java。甲字典 类有两个重要的方法Dictionary.keys()和Dictionary.elements()吨帽子可以通过迭代计数。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