[問題] Hashtable<String,Integer> 取數字

看板java作者 (。.。)時間15年前 (2010/04/22 23:18), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/3 (看更多)
首先 資料存在Hashtable中 Hashtable<String,Integer> table = new Hashtable<String,Integer>(); 我要依序取出Hashtable中的key與value存到資料庫 然後就 Set<Entry<String, Integer>> t = table.entrySet(); Iterator it = t.iterator(); while (it.hasNext()){ Entry entry = (Entry) it.next(); String word = (String) entry.getKey(); int times = (int)entry.getValue(); //----> Object無法轉換成int // float tf = (float)times/numToken; // ---> 尷尬 Orz ..... } 我不知道該怎麼寫 才能依序取出我在Hashtable中的資料 並分別給予 String/int 型態 因為我Hashtable中的value是我要拿來做運算用的 所以不能是object 只想到很蠢的方式 : 拿出word後再反查hashtable 去getValue ... 不知道有沒有比較好的寫法呢? 謝謝解答 :) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.88.241
文章代碼(AID): #1Bq6Yo6e (java)
討論串 (同標題文章)
文章代碼(AID): #1Bq6Yo6e (java)