# string.toUpperCase() behaving weirdly

**URL:** <https://discourse.processing.org/t/string-touppercase-behaving-weirdly/15321>\
**Category:** Beginners\
**Created:** [November 7, 2019, 5:03pm UTC](https://discourse.processing.org/t/string-touppercase-behaving-weirdly/15321 "2019-11-07T17:03:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [November 7, 2019, 5:03pm UTC](https://discourse.processing.org/t/string-touppercase-behaving-weirdly/15321/1 "2019-11-07T17:03:59Z")

</div>

I was trying to make an if statement that checks a string but isn’t case sensitive, and I came across some weird behavior:

```auto
String str = "Hello World.";

void setup(){
  println(str.toUpperCase()); //Outputs HELLO WORLD.
  
  println(str.toUpperCase() == "HELLO WORLD."); //Outputs false 
  println(str.toUpperCase() == str.toUpperCase()); //Outputs false (?!)

  //The same thing also happens to .toLowerCase()
}

```

Why do these second two print statements output false?  
And how would I go about checking if a string matches in a condition which isn’t case sensitive?

Sidenote: this sort of code works in Javascript

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 7, 2019, 5:10pm UTC](https://discourse.processing.org/t/string-touppercase-behaving-weirdly/15321/2 "2019-11-07T17:10:20Z")

</div>

You can’t use == with String

Please use str.toUpperCase().equals(“Hello”) instead

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [November 7, 2019, 5:12pm UTC](https://discourse.processing.org/t/string-touppercase-behaving-weirdly/15321/3 "2019-11-07T17:12:30Z")

</div>

Thanks.

```auto

```

---

<div class="post-metadata">

**Author:** ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)\
**Post date:** [November 7, 2019, 5:19pm UTC](https://discourse.processing.org/t/string-touppercase-behaving-weirdly/15321/4 "2019-11-07T17:19:21Z")

</div>

On [String / Reference / Processing.org](https://processing.org/reference/String.html) is explained why:

> 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](https://github.com/processing/processing/wiki/Troubleshooting#why-dont-these-strings-equal) reference has a longer explanation.)
