看板 java 關於我們 聯絡資訊
已爬文 http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/HashMap.htm 根據上面基本的Hashtable(Hashmap)教學, 宣告 Hashtable<String,Integer> test=new Hashtable<String,Integer>(); 我知道這樣是一個key->value 那如果要兩個key對一個value呢? 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.133.92
tkcn:HashMap<String, HashMap<String, Integer>> 這個如何? 03/04 20:15
tstanly:謝謝 但這樣怎麼去put啊..test.put(key1, ? ) 03/04 20:41
tstanly:一樓的意思是 宣告兩個hashtable 第二個hashtable當第一個 03/04 20:59
tstanly:參數嗎? 03/04 21:00
PsMonkey:不然 HashMap<TwoString, Integer> 呢? XDXD 03/04 22:52
tkcn:不是兩個hashtable,而是有幾個key1就有幾個hashtable (再+1) 03/04 22:52
tkcn:至於 put/get,只要你明白我真正的意思,都並不難實作 03/04 22:53
tkcn:如果兩個key都是string,自己用個特殊符號(如,)連起來也可以 03/04 22:55
tstanly:那請問如果test<key,value> value要怎麼讓他加1啊 03/04 23:09
tstanly:例如遇到某個key的時候 就讓他value加1 03/04 23:10
tkcn:先解這問題:如果put兩個相同key會怎樣?先知道行為再想怎麼做 03/04 23:29
tstanly:所以是先get出來 +1 然後remove key 在put進去放新的值? 03/04 23:49
tkcn:所以你能回答上面那個問題了嗎? 03/04 23:50
tstanly:put兩個相同key的話...應該會有error吧= =? 覆蓋? 03/04 23:54
tkcn:API 不是寫得很清楚嗎 ~_____~ 03/05 00:01
tstanly:return the previous value of the specified key in this 03/05 00:12
tstanly:hashtable, or null if it did not have one 03/05 00:13
tkcn:好吧,算我錯,HashMap 的才有寫 http://tinyurl.com/y9qepg2 03/05 00:18
tstanly:謝謝樓上^^ 03/05 00:42