# Make string from characters

**URL:** <https://discourse.processing.org/t/make-string-from-characters/16563>\
**Category:** Beginners\
**Created:** [December 22, 2019, 1:32am UTC](https://discourse.processing.org/t/make-string-from-characters/16563 "2019-12-22T01:32:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![quinten](https://avatars.discourse-cdn.com/v4/letter/q/7feea3/32.png) [@quinten](https://discourse.processing.org/u/quinten)\
**Post date:** [December 22, 2019, 1:32am UTC](https://discourse.processing.org/t/make-string-from-characters/16563/1 "2019-12-22T01:32:54Z")

</div>

Hi everyone, why is the following not true (“ab” == str(‘a’) + str(‘b’)) and how can I adjust it so that it will be true? See the example below:

```auto
void setup() {
  size(200, 200);
}

void draw() {
    println("ab", str('a') + str('b'), "ab" == str('a') + str('b'));
    exit();
}

```

Thanks,  
Q

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 22, 2019, 2:49am UTC](https://discourse.processing.org/t/make-string-from-characters/16563/2 "2019-12-22T02:49:46Z")

</div>

```auto
void setup() {
  size(200, 200);
}

void draw() {
    println("ab", str('a') + str('b'), ( "ab".equals(str('a') + str('b') ) ) );
    exit();
}

```

console: `ab ab true`

[https://processing.org/reference/String\_equals\_.html](https://processing.org/reference/String_equals_.html)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 22, 2019, 2:52am UTC](https://discourse.processing.org/t/make-string-from-characters/16563/3 "2019-12-22T02:52:50Z")

</div>

[https://processing.org/reference/String\_equals\_.html](https://processing.org/reference/String_equals_.html)

🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [January 7, 2020, 1:19am UTC](https://discourse.processing.org/t/make-string-from-characters/16563/4 "2020-01-07T01:19:48Z")

</div>

Just to underscore the above links and examples, calling `"mystring".equals("mystring")` rather than `"mystring"=="mystring"` is necessary because, as the reference states:

> it’s not possible to compare strings using the equality operator (==). Returns **true** if the strings are the same and **false** if they are not. [equals() / Reference / Processing.org](https://processing.org/reference/String_equals_.html)

This is inherited from Java, in which Strings are immutable objects and the `==` operator compares their memory addresses rather than their contents. The result is really unpleasant – depending on your code, you might accidentally get `==` to work on strings, but not for the reasons you think. Just don’t do it.

> <https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java>

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [January 7, 2020, 3:00am UTC](https://discourse.processing.org/t/make-string-from-characters/16563/5 "2020-01-07T03:00:17Z")

</div>

Just adding for future references: [Troubleshooting: why-dont-these-strings-equal](https://github.com/processing/processing/wiki/troubleshooting#why-dont-these-strings-equal).

Kf
