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




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.