Skip to content

Commit 45bb3c7

Browse files
authored
Merge pull request #578 from twisst/main
Fixes for clarity and broken link in 'Strings and Drawing Text' #576
2 parents 42051af + b7fd5e8 commit 45bb3c7

File tree

1 file changed

+12
-2
lines changed
  • content/tutorials/text/strings-and-drawing-text

1 file changed

+12
-2
lines changed

content/tutorials/text/strings-and-drawing-text/index.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,17 @@ println(uppercase);
6969

7070
You might notice something a bit odd here. Why didn't we simply say `message.toUpperCase()` and then print `message` variable? Instead, we assigned the result of `message.toUpperCase()` to a new variable with a different name—`uppercase`.
7171

72-
This is because a String is a special kind of object. It is immutable. An immutable object is one whose data can never be changed. Once we create a String, it stays the same for life. Anytime we want to change the String, we have to create a new one. So in the case of converting to uppercase, the method `toUpperCase()` returns a copy of the String object with all caps.
72+
This is because a String is a special kind of object. It is immutable. An immutable object is one whose data can never be changed. Once we create a String, it stays the same for life. Anytime we want to change the String, we have to assign it to a variable.
73+
74+
So in the case of converting to uppercase, the method `toUpperCase()` cannot modify the original String in message. It only returns a *new copy* of the String object with all caps.
75+
76+
Note that it is possible to use the existing variable `message` to store this new String:
77+
78+
```
79+
message = message.toUpperCase();
80+
```
81+
82+
You might be thinking, "Wait, didn’t you just say Strings are immutable?" Yes, that’s true. The code above doesn’t change the original String. Instead, it updates the `message` variable to point to the new String object created by `toUpperCase()`. Without this reassignment (using the `=` operator), the original `message` would remain unchanged.
7383

7484
Finally, let's look at [equals()](http://processing.org/reference/String_equals_.html). Now, Strings can be compared with the `==` operator as follows:
7585

@@ -503,7 +513,7 @@ class Letter {
503513
}
504514
```
505515

506-
The character by character method also allows us to display text along a curve. Before we move on to letters, let's first look at how we would draw a series of boxes along a curve. This example makes heavy use of [Trignometry](http://www.processing.org/learning/trig/).
516+
The character by character method also allows us to display text along a curve. Before we move on to letters, let's first look at how we would draw a series of boxes along a curve. This example makes heavy use of [trigonometry](https://processing.org/reference/#math-trigonometry).
507517

508518
[Example: Boxes along a curve](http://learningprocessing.com/examples/chp17/example-17-07-boxesoncurve)
509519

0 commit comments

Comments
 (0)