[問題] Hashtable<String,Integer> 取數字
首先 資料存在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
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1 之 3 篇):