Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala

How to convert a string to lower and uppercase in Scala

Samia Ishaque

Overview

The methods toUpperCase and toLowerCase are used to convert strings to upper and lowercase respectively. The methods take a string and either convert all the letters to upper or lowercase.

The following is the definition of toUpperCase in Scala:

String toUpperCase()

The following is the definition of toLowerCase in Scala:

String toLowerCase()

Parameters

Both toUpperCase and toLowerCase do not take any input parameters.

Return value

toUpperCase returns a string in all uppercase letters, and toLowerCase returns a string in all lowercase letters.

Example

The following is an example of how you can use the methods toUpperCase and toLowerCase to convert strings:

object Main extends App {
    val str = "Hello World!"
    val lowerstr = str.toLowerCase()
    val upperstr = str.toUpperCase()

    print("In lowercase: " + lowerstr + "\n")
    print("In uppercase: " + upperstr)
}

RELATED TAGS

scala

CONTRIBUTOR

Samia Ishaque
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring