The Java String toLowerCase() function is a built-in method that converts all the characters in a given string to lowercase. This function returns a new string with all the uppercase characters in the original string converted to lowercase. The toLowerCase() function is useful when comparing strings in a case-insensitive manner or when normalizing user input. It is important to note that the toLowerCase() function does not modify the original string, but instead returns a new string with the converted characters. Keep reading below to learn how to Java String toLowerCase in Kotlin.

Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!

Buy Now On Amazon

Java String toLowerCase in Kotlin With Example Code

Java String toLowerCase() method is used to convert all the characters in a string to lowercase. In Kotlin, we can use this method by calling it on a string variable.

To use the toLowerCase() method in Kotlin, we can simply call it on a string variable like this:


val str = "HELLO WORLD"
val lowerCaseStr = str.toLowerCase()

In the above example, we have a string variable named “str” which contains the value “HELLO WORLD”. We then call the toLowerCase() method on this variable and assign the result to a new variable named “lowerCaseStr”. The value of “lowerCaseStr” will be “hello world”.

It is important to note that the toLowerCase() method does not modify the original string. Instead, it returns a new string with all the characters converted to lowercase.

We can also use the toLowerCase() method with a Locale parameter to specify the locale to use for the conversion. For example:


val str = "HELLO WORLD"
val lowerCaseStr = str.toLowerCase(Locale.getDefault())

In the above example, we are using the getDefault() method of the Locale class to get the default locale for the system. We then pass this locale as a parameter to the toLowerCase() method.

In conclusion, the toLowerCase() method is a useful method in Kotlin for converting all the characters in a string to lowercase. It is easy to use and can be used with or without a Locale parameter.

Equivalent of Java String toLowerCase in Kotlin

In conclusion, the Kotlin programming language provides a convenient and efficient way to convert strings to lowercase using the `toLowerCase()` function. This function works similarly to the equivalent Java String `toLowerCase()` function, but with the added benefit of being more concise and readable. By using this function, Kotlin developers can easily manipulate strings and ensure that they are in the correct case format for their specific use case. Overall, the `toLowerCase()` function in Kotlin is a valuable tool for any developer working with strings and looking to streamline their code.

Contact Us