Scala String toLowerCase() Method with Example

Here, we will learn about the toLowerCase() method in Scala. It is used to convert the character of the string to lowercase, 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 toLowerCase() Method

The toLowerCase() method in Scala is used to convert the string's character to lowercase characters.

Example:

InitialString = "SCALA Programming"
LowerCaseString = "scala programming"

Syntax:

string_Name.toLowerCase()

Parameters: The method does not accept any parameter.

Return Value: It returns a string which is the lower case conversion of the given string.

Example 1: Program to convert string to lowercase

object MyClass {
    def main(args: Array[String]) {
        val myString = "SCALA Programming"
        println("Original string is '" + myString + "'")
    
        val lowerCaseString = myString.toLowerCase()
        println("Lower Case String is '" + lowerCaseString + "'")
    }
}

Output:

Original string is 'SCALA Programming'
Lower Case String is 'scala programming'

Example 2: Program to convert string with extra character to lowercase

object MyClass {
    def main(args: Array[String]) {
        val myString = "#Learning-SCALA!"
        println("Original string is '" + myString + "'")
    
        val LowerCaseString = myString.toLowerCase()
        println("Lower Case String is '" + LowerCaseString + "'")
    }
}

Output:

Original string is '#Learning-SCALA!'
Lower Case String is '#learning-scala!'



Comments and Discussions!

Load comments ↻






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