下面的Java代碼:哈希表的值不increaing
public class TestCSVDataToMap {
public static Hashtable<String, Integer> testTable = new Hashtable<>();
public static void main (String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("test.csv"));
String line;
while ((line = reader.readLine()) != null) {
String symbol = "0";
if(testTable.contains(symbol)) {
int value = testTable.get(symbol);
value++;
testTable.put(symbol, value);
}
else {
System.out.println("dash!");
testTable.put(symbol, 1);
}
}
System.out.println(testTable);
}
}
具有輸出:
dash!
dash!
dash!
dash!
{0=1}
爲什麼關鍵的不是值「0」時長將.csv文件是解析?在testTable(一個Hashtable)中,它被初始化爲(0,1),並且該值應該保持增長,因爲該符號總是被檢測爲'0'的關鍵字。
「test.csv」的內容是什麼? – rgettman 2014-10-08 16:56:12
@rgettman你不需要它,程序的輸出足以看到問題(解析時實際使用的是哪一行?) – msrd0 2014-10-08 16:57:11
只是多行數據,這不是問題,我只是用它來使'而'邏輯持續多次。 – byteBiter 2014-10-08 16:58:08