in a tutorial (for implementing a xml parser) i saw the following code:
if( \"NODENAME\".equals(xmlreader.getNodeName()) ) { // getNodeName() returns java.l
If you have the impression that you could also compare the Strings using ==
then it would fail even if in the comparison would be involved two "meaningfully" equal String, since ==
checks if it is the same Object. Of course, as the other answers state, you avoid a NullPointeException
if you call equals on a standard String, as in your question.