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()
Both toUpperCase
and toLowerCase
do not take any input parameters.
toUpperCase
returns a string in all uppercase letters, and toLowerCase
returns a string in all lowercase letters.
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
CONTRIBUTOR
View all Courses