ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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!'
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.