{{{ #!html
Java Programing - Map 用法
使用Map介面之實做類別 Hashtable
}}} [[PageOutline]] 要達成 Map 的 key value 對應程式,也可以用hashmap,不過hashmap的功能與選項較多,因此挑較單純的hashtable來使用 * 用法: {{{ 要加入元素用 map.put(key,value); 要取出元素用 map.get(key); }}} * Example : {{{ #!java String[] key = { "this is a cat", "this is a dog", "this is a fish", }; int[] value = { 1, 2, 3 }; Hashtable table = new Hashtable(); for (int i = 0;i < key.length ; i++){ table.put(key[i], value[i]); } System.out.println("value = " + table.get("this is a ")); }}}