弦乐似乎并不等同于Java的Andr​​oid上,尽管它们打印相同并不、弦乐、Java、Andr

由网友(暮光沉寂i)分享简介:我已经得到了我相当困惑的一个问题。我有code以下线在我的Andr​​oid应用程序:I've got a problem that I'm rather confused about. I have the following lines of code in my android application:Sys...

我已经得到了我相当困惑的一个问题。我有code以下线在我的Andr​​oid应用程序:

I've got a problem that I'm rather confused about. I have the following lines of code in my android application:

System.out.println(CurrentNode.getNodeName().toString());
if (CurrentNode.getNodeName().toString() == "start") {
    System.out.println("Yes it does!");
} else {
    System.out.println("No it doesnt");
}

当我看到第一个println语句,它在LogCat中显示为开始(不带引号明显)的输出。但是当if语句执行它转到else语句,并打印不,没有关系。

When I look at the output of the first println statement it shows up in LogCat as "start" (without the quotes obviously). But then when the if statement executes it goes to the else statement and prints "No it doesn't".

我想知道,如果节点的名称可能有某种在其非打印字符,所以我检查从getNodeName()传来的字符串的长度,这是5个字符,如你所愿。

I wondered if the name of the node might have some kind of non-printing character in it, so I've checked the length of the string coming from getNodeName() and it is 5 characters long, as you would expect.

有没有人有任何想法是怎么回事?

Has anyone got any idea what's going on here?

推荐答案

使用字符串的equals方法来比较字符串。该 == 运营商将只比较对象引用。

Use String's equals method to compare Strings. The == operator will just compare object references.

if ( CurrentNode.getNodeName().toString().equals("start") ) {
   ...
阅读全文

相关推荐

最新文章