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
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短