下面的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