KOTLIN Tutorial



STRINGS IN KOTLIN


Strings in Kotlin

Strings in Kotlin are objects that represent sequences of characters. You can use them like in most modern languages, but Kotlin also gives you some powerful tools!


1. Declaring Strings

val name = "Kotlin"
val greeting = "Hello, $name!"
println(greeting)
  

Output: Hello, Kotlin!

๐Ÿ’ก Tip: $variable is used for String Templates in Kotlin.

2. Multiline Strings

Kotlin allows you to write strings over multiple lines using triple quotes """.

val message = """
    Dear User,
    Welcome to Kotlin Tutorials!
    Regards,
    Team
""".trimIndent()

println(message)
  

3. String Properties & Functions

Strings are objects with properties and methods:

val language = "Kotlin"
println(language.length)         // Number of characters
println(language.uppercase())    // KOTLIN
println(language.lowercase())    // kotlin
println(language.reversed())     // niltoK
  
๐Ÿ” Use these functions to manipulate and inspect strings easily.

4. String Comparison

val a = "Hello"
val b = "hello"

println(a == b)         // false (case-sensitive)
println(a.equals(b, ignoreCase = true))  // true
  

5. String Iteration

You can loop through each character in a string using a for loop:

val text = "Kotlin"

for (char in text) {
    print("$char ")
}
  

Output: K o t l i n


๐Ÿงช Try It Yourself

Use these quick challenges to practice:

  • Create a multiline message with your name.
  • Reverse your name using reversed().
  • Check if two strings are equal ignoring case.

๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review