This is the fifth part of the video series on Kotlin language.
Read and watch the other parts here.
1. | Hello Kotlin |
2. | Declaring Variables |
3. | Data Types |
4. | String (Part 1) |
In this video, we discuss string comparison and string templates.
String comparison is a breeze in Kotlin. We can use == to compare two string literals.
fun main(args:Array<String>){ var lang1 = "java" var lang2 = "Java" println(lang1 == lang2) }
Strings can be compared using the .compareTo method too, which gives you an option to compare the values ignoring the case, like this.
println(lang1.compareTo(lang2,true) == 0)
String templates allow you to embed values in a string using ${expression}
var comments = "$lang1 is cool" println(comments) comments = "${lang2} is cool" println(comments)
You can find the video here.