我试图将以下行保存到不同的数组中:
1908,Souths,Easts,Souths,Cumberland,Y,14,12,4000
我使用的代码为year[i]
提供了整数值,但为winningScore[i]
,loosingScore[i]
和crowd[i]
提供了零值。有人可以帮我吗?我的代码如下:
str[i] = inputFile.nextLine();
StringTokenizer tok = new StringTokenizer(str[i], ",");
while (tok.hasMoreTokens()) {
year[i] = Integer.parseInt (tok.nextToken());
winteam[i] = tok.nextToken();
loosingteam[i] = tok.nextToken();
minor[i] = tok.nextToken();
wooden[i] = tok.nextToken();
held[i] = tok.nextToken();
if(held[i] == "Y") {
winningScore[i] = Integer.parseInt (tok.nextToken());
loosingScore[i] = Integer.parseInt (tok.nextToken());
crowd[i] = Integer.parseInt (tok.nextToken());
}
else {
break;
}
}
答案 0 :(得分:2)
==
用于等于两个引用,Object#equals
方法用于等于两个Object
。
if(held[i] == "Y")
字符串等于需要使用等于
if(held[i].equals("Y")){...}