- Kotlin - Home
- Kotlin - Overview
- Kotlin - Environment Setup
- Kotlin - Architecture
- Kotlin - Basic Syntax
- Kotlin - Comments
- Kotlin - Keywords
- Kotlin - Variables
- Kotlin - Data Types
- Kotlin - Operators
- Kotlin - Booleans
- Kotlin - Strings
- Kotlin - Arrays
- Kotlin - Ranges
- Kotlin - Functions
- Kotlin Control Flow
- Kotlin - Control Flow
- Kotlin - if...Else Expression
- Kotlin - When Expression
- Kotlin - For Loop
- Kotlin - While Loop
- Kotlin - Break and Continue
- Kotlin Collections
- Kotlin - Collections
- Kotlin - Lists
- Kotlin - Sets
- Kotlin - Maps
- Kotlin Objects and Classes
- Kotlin - Class and Objects
- Kotlin - Constructors
- Kotlin - Inheritance
- Kotlin - Abstract Classes
- Kotlin - Interface
- Kotlin - Visibility Control
- Kotlin - Extension
- Kotlin - Data Classes
- Kotlin - Sealed Class
- Kotlin - Generics
- Kotlin - Delegation
- Kotlin - Destructuring Declarations
- Kotlin - Exception Handling
Kotlin String - lowercase() Function
The Kotlin string lowercase() function returns a copy of the current string that is converted to lowercase using the rules of the default locale or the specified locale. This function is especially used when working with text processing, user input validation, and formatting.
If the string contains characters that do not have lowercase forms, such as numbers or punctuation marks, they remain unchanged.
This function serves as a replacement for the toLowerCase() function, which has been deprecated.
Syntax
Following is the syntax of the Kotlin string lowercase() function −
fun String.lowercase(locale: Locale): String
Parameters
This function accepts an optional parameter which is a locale object representing the specific locale used for the conversion. If not provided it uses the system's default locale.
Return value
This function returns a string which is lower case of this string.
Example 1: Convert String into Lowercase
Following is the basic example, we use lowercase() to make the string lower case −
fun main() {
val string = "TUTORIALSPOINT, India"
// use lowercase()
val lowerCase = string.lowercase()
println("lowerCase of the string: " + lowerCase)
}
Output
Following is the output −
lowerCase of the string: tutorialspoint, india
Example 2: Use Specific Locale
In this example, we pass the specific locale to the lowercase() function to convert the string into lowercase −
import java.util.Locale
fun main(){
val input = "HELLO, KOTLIN!"
val lowercaseString = input.lowercase(Locale.UK)
println(lowercaseString)
}
Output
Following is the output −
hello, kotlin!