Scala String toUpperCase() Method with Example

Here, we will learn about the toUpperCase() method in Scala. It is used to convert the character of the string to uppercase, we will see its syntax and working example.
Submitted by Shivang Yadav, on January 27, 2021

String is an immutable collection that stores sequences of characters.

String toUpperCase() Method

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: Program to 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: Program to 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!'


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.