将String数组元素与文字字符串进行比较

时间:2014-04-23 09:09:35

标签: java

我在这里做错了什么:

public void processFinish(String[] result)
{
    System.out.println(result[0]);
    System.out.println(result[1]);
    System.out.println(result[2]);

    if(result[0] == "true")
        comments.setText("Success");
    else if (result[1] == "true" && result[2] == "false")
        comments.setText("Username is already used");
    else
        comments.setText("Phone number is already used");
}

输出是: 真正 假 假

然而,它总是执行else子句!!!

1 个答案:

答案 0 :(得分:3)

用它来比较

if(result[0].equals("true"))
        comments.setText("Success");
    else if (result[1].equals("true") && result[2].equals("false"))
        comments.setText("Username is already used");
    else
        comments.setText("Phone number is already used");