Friday, May 31, 2019

Java String - 1 is not 1?

I'm a c++ programmer who wrote some php server code to be translated to java and pretty new to Java. But it feels quite common coming from c++.
I have a server up and running and this code:


String req = "1";
Document doc = loadXMLFromString (req);
Element root = doc.getDocumentElement(); // "xml"
// check version
Element e = firstChildElement (root, "version");
String result = e.getTextContent(); // returns "1"!
String expected = "1";
if (result != expected)
{
out.printLn ("wrong version: (" + result + "), expected: (" + expected + ")!");
return;
}

This prints "wrong version: (1), expected (1)". The same holds with if (result != "1").
Now even the debugger (eclipse) shows that result is actually "1", so I'm truly lost here.
I seem to be missing the obvious but just can't see it...can you help pls? Thanks!

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...