By IncludeHelp Last updated : October 22, 2024
Scala String toUpperCase() Method
By IncludeHelp Last updated : October 22, 2024
Description and Usage
The toUppercase() method in Scala is used to convert the string's character to uppercase characters.
Example:
InitialString = "Scala programming"
upperCaseString = "SCALA PROGRAMMING"
Syntax
string_Name.toUpperCase()
Parameters
The method does not accept any parameter.
Return Value
It returns a string which is the upper-case conversion of the given string.
Example 1: Convert string to uppercase
object MyClass {
def main(args: Array[String]) {
val myString = "Scala programming"
println("Original string is '" + myString + "'")
val upperCaseString = myString.toUpperCase()
println("Upper Case String is '" + upperCaseString + "'")
}
}
Output
Original string is 'Scala programming'
Upper Case String is 'SCALA PROGRAMMING'
Example 2: Convert string with extra character to uppercase
object MyClass {
def main(args: Array[String]) {
val myString = "#learning-Scala!"
println("Original string is '" + myString + "'")
val upperCaseString = myString.toUpperCase()
println("Upper Case String is '" + upperCaseString + "'")
}
}
Output
Original string is '#learning-Scala!'
Upper Case String is '#LEARNING-SCALA!'