如何在整数数组中保存标记?

时间:2013-05-17 05:47:07

标签: java

我试图将以下行保存到不同的数组中:

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;
    }
}

1 个答案:

答案 0 :(得分:2)

==用于等于两个引用,Object#equals方法用于等于两个Object

if(held[i] == "Y")字符串等于需要使用等于

的方法
if(held[i].equals("Y")){...}