Start learning free

LESSON 65 OF 348 · STRINGS I

Uppercase and Lowercase in Scala in Scala

Lesson

In Scala, String objects have built-in methods to change their case:

s.toUpperCase()   // converts all characters to uppercase
s.toLowerCase()   // converts all characters to lowercase

Here are some examples:

var word = "Hello World"
var upper = word.toUpperCase()  // "HELLO WORLD"
var lower = word.toLowerCase()  // "hello world"

var name = "ALICE"
println(name.toLowerCase())  // "alice"

These methods return a new String — the original is not modified.


Assignment
Follow the Coding Tutorial and convert word to both uppercase and lowercase!


Hint
Use word.toUpperCase() and word.toLowerCase().

STEP 1 OF 2
    Ctrl + Enter to check

    String Upper Lower in Scala

    Keep going with ScalaAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free