Friday 31 May 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...