-1
while (currentNode != null) {

   Letter currentLetter = currentNode.getElement();

   if (currentLetter.decorator() != "!") {

      return false;

   }

   currentNode = currentNode.getNext();

}

return true;

In the attached picture, you can see currentLetter.decorator() = "!", so the if statement should evaluate to false, but the method returns false immediately, meaning the if branch somehow executed. This really shouldn't be that difficult, I must be missing something small because I have no idea why this is happening. Any help would be much appreciated.

Picture of the code

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Oliver
  • 1
  • 2

1 Answers1

-1

Use .equals() (or its inversion) to compare strings in Java not == or != . Otherwise you are comparing the instances of the String (whether they are the same object), not the String contents (whether they have the same value).

For details, see here.

abligh
  • 24,573
  • 4
  • 47
  • 84