# What does if(!VARIABLE.equalsVARIABLE) mean?

**URL:** <https://discourse.processing.org/t/what-does-if-variable-equalsvariable-mean/2541>\
**Category:** Coding Questions\
**Created:** [August 10, 2018, 6:30pm UTC](https://discourse.processing.org/t/what-does-if-variable-equalsvariable-mean/2541 "2018-08-10T18:30:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![B4ko](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@B4ko](https://discourse.processing.org/u/B4ko)\
**Post date:** [August 10, 2018, 6:30pm UTC](https://discourse.processing.org/t/what-does-if-variable-equalsvariable-mean/2541/1 "2018-08-10T18:30:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 10, 2018, 6:40pm UTC](https://discourse.processing.org/t/what-does-if-variable-equalsvariable-mean/2541/2 "2018-08-10T18:40:15Z")

</div>

[Processing.org/reference/logicalNOT.html](http://Processing.org/reference/logicalNOT.html)

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 10, 2018, 8:56pm UTC](https://discourse.processing.org/t/what-does-if-variable-equalsvariable-mean/2541/3 "2018-08-10T20:56:43Z")

</div>

Shameless self-promotion: here is a guide on `boolean` values, operators, and `if` statements that explains what’s going on:

> **[If Statements](https://happycoding.io/tutorials/processing/if-statements)**
>
> Learn how to use if statements to make decisions in your code.

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [August 10, 2018, 8:56pm UTC](https://discourse.processing.org/t/what-does-if-variable-equalsvariable-mean/2541/4 "2018-08-10T20:56:52Z")

</div>

About `.equals()`:

> 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](http://wiki.processing.org/w/Troubleshooting#Why_don.27t_these_Strings_equal.3F) reference has a longer explanation.)

(from [String / Reference / Processing.org](https://processing.org/reference/String.html))

Here a small demo:

```auto
String a = "cat";
String b = "c";
b += "at";

println("a =", a);
println("b =", b);
println();

println("a == b ?");
println(a == b);
println();

println("a.equals(b) ?");
println(a.equals(b));

```

prints the following:

```auto
a = cat
b = cat

a == b ?
false

a.equals(b) ?
true

```

The demo at the String documentation page [no longer works as expected](https://github.com/processing/processing-docs/issues/636) because of Java String interning.
