0

I'm using the results from String targetID = ((Node) targetId.item(0)).getNodeValue() in some if logic: if (targetID == "OK") and else if (targetID == "UNKNOWN_USER"), but both comparisons fail. I print out targetID and it displays correctly and displays as java.lang.String, so what am I missing here?

4

1 回答 1

4

Use equals() and not == for string comparison:

if (targetID.equals("OK")) { ... }

etc.

s1 == s2 compares references, which is rarely what you want when comparing strings.

于 2013-03-06T17:52:10.720 回答