String interpolation

A string is a most commonly and heavily used class. String literal is also an instance of the string class. String interpolation has the most beautiful features in Kotlin.

Interpolation is basically smart string concatenation. A typical string concatenation can look as follows:

    val name="Kotlin Blueprints"    println("Name $name")

In Android, there can be many cases where we do string concatenation and string interpolation can help us.

Remember! We have to display dynamic labels on TextView countless times in the app. The code for that using string interpolation can look as follows:

    txtFollowers.text = "$followersCount          ${getString(R.string.cnt_followers)}"    txtFriendsCount.text = "$friendsCount        ${getString(R.string.

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.