Hey everyone! Can someone help me understand the below code?
buttonOneText
buttonTwoText
levelNumber
are all variables I declared earlier
if (!buttonTwoText[levelNumber].equals(buttonOneText[levelNumber]))
In short, when there is a ‘!’ inside the ‘if’ clause and there is also an ‘.equals’ inside the same clause. What are these doing to the ‘if’ clause exactly?
To compare the contents of two Strings, use the equals() method, as in if (a.equals(b)), instead of if (a == b). A String is an Object, so comparing them with the == operator only compares whether both Strings are stored in the same memory location. Using the equals() method will ensure that the actual contents are compared. (The troubleshooting reference has a longer explanation.)