skip to Main Content
fun main()
{
var txt = "Hello World"
println(txt.toUpperCase())  
println(txt.toLowerCase())  
}


Error:
D:kt>kotlinc  Upper_Lower_case.kt
Upper_Lower_case.kt:4:13: warning: 'toUpperCase(): String' is deprecated. Use uppercase() instead.
println(txt.toUpperCase())
            ^
Upper_Lower_case.kt:5:13: warning: 'toLowerCase(): String' is deprecated. Use lowercase() instead.
println(txt.toLowerCase())

Using kotlin 1.8.22 version using command prompt , toUpperCase() and toLowerCase() not working reason

2

Answers


  1. Chosen as BEST ANSWER
    fun main()
    {
    var txt = "Hello World"
    println(txt.uppercase())  
    println(txt.lowercase())  
    }
    

  2. kotlin 1.8.0

    fun main() {
            val str = "Hello, World!"
            val upperCaseStr = str.uppercase(Locale.getDefault())
            val lowerCaseStr = str.lowercase(Locale.getDefault())
        
            println("Original String: $str")
            println("Uppercase String: $upperCaseStr")
            println("Lowercase String: $lowerCaseStr")
        
            val char = 'a'
            val upperCaseChar = char.uppercaseChar()
            val lowerCaseChar = char.lowercaseChar()
        
            println("Original Char: $char")
            println("Uppercase Char: $upperCaseChar")
            println("Lowercase Char: $lowerCaseChar")
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search