Ⅰ 問下java里Hashtable的用法
Hashtable<String,A> hb = new Hashtable();
A instA = new A();
String key = new String(instA.a & instA.b);
hb.put(key,instA);
Ⅱ java中的Hashtable怎麼用,請詳細舉例子說明,拜託了 謝謝
就是哈希表,下抄面這個示例創建襲了一個數字的哈希表。它將數字的名稱用作鍵: Hashtable<String, Integer> numbers = new Hashtable<String, Integer>();
numbers.put("one", 1);
numbers.put("two", 2);
numbers.put("three", 3);
要獲取一個數字,可以使用以下代碼:
Integer n = numbers.get("two");
if (n != null) {
System.out.println("two = " + n);
}