August 2017
Intermediate to advanced
440 pages
10h
English
Building strings is an easy process, but in Java it usually requires long concatenation expressions. Let's jump straight to an example. Here is a string built from multiple elements implemented in Java:
//Java String name = "Eva"; int age = 27; String message = "My name is" + name + "and I am" + age + "years old";
In Kotlin, we can greatly simplify the process of string creation by using string templates. Instead of using concatenation, we can simply place a variable inside a string, using a dollar character to create a placeholder. During interpolation, string placeholders will be replaced with the actual value. Here is an example:
val name = "Eva" val age = 27 val message = "My name is $name and I am $age years old" println(message) ...
Read now
Unlock full access