Skip to content

Commit 63bab3a

Browse files
committed
Locales
1 parent 2bf4f4f commit 63bab3a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/strings_ii/UPPERCASE.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ void main() {
1212
}
1313
```
1414

15-
This does not change the original `String` in place. It just makes a new `String` with all upper-case letters.
15+
This does not change the original `String` in place. It just makes a new `String` with all upper-case letters.
16+
17+
Much like with `.toLowerCase()` you can optionally provide a `Locale` to get consistent behavior
18+
no matter what language the system is set to.
19+
20+
```java
21+
void main() {
22+
String message = "Happy Valentines Day";
23+
24+
String upperCased = message.toUpperCase(Locale.US);
25+
IO.println(upperCased);
26+
}
27+
```

src/strings_ii/lowercase.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void main() {
1616

1717
This does not change the original `String` in place. It just makes a new `String` with all lower-case letters.
1818

19-
What about other languages? Many of them also have a distinction between uppercase and lowercase, and usually, `.toLowerCase()` does the right thing for them too:
19+
Many other languages also have a distinction between upper-case and lower-case and, usually, `.toLowerCase()` does the "right thing" for them too:
2020

2121
```java
2222
~void main() {
@@ -25,4 +25,18 @@ IO.println("ПРИВЕТ".toLowerCase()); // prints "привет"
2525
~}
2626
```
2727

28-
However, in different languages, the mapping between uppercase and lowercase characters can differ. For example, in Turkish, the lowercase form of the letter `I` is `ı` without a dot. By default, Java uses the rules for the language of the operating system, so `"I".toLowerCase()` will return `"i"` on an English system and `"ı"` on a Turkish one.
28+
In different languages the mapping between upper-case and lower-case letters can differ.
29+
30+
For example, in Turkish the lower-case form of the letter `I` is `ı` and not `i`.
31+
By default, Java uses the rules for the language of the computer it is running on.
32+
So `"I".toLowerCase()` will return `"i"` on an English system and `"ı"` on a Turkish one.
33+
34+
To get behavior that is consistent regardless of the machine it is being run on
35+
you can pass use an explicit `Locale`.
36+
37+
```java
38+
~void main() {
39+
IO.println("I".toLowerCase(Locale.US)); // i - on every computer
40+
IO.println("I".toLowerCase(Locale.forLanguageTag("tr-TR"))); // ı - on every computer
41+
~}
42+
```

0 commit comments

Comments
 (0)