"A", "an", "An", "the", "The") val numbers = listOf("one", "two", "three", "four") val numbersMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3, "key4" to 1) //mutable interface val set = mutableSetOf(1, 2, 3) val numbers = mutableListOf(1, 2, 3, 4) val numbersMap = mutableMapOf("one" to 1, "two" to 2)
= null // compilation error var b: String? = "abc" b = null // ok print(b) val l = b?.length ?: -1 // Using Elvis Operator val l = b?.length // Using Safe Call val l = b!!.length // Non null Operator
age: Int) Data classes have to fulfill the following requirements: • The primary constructor needs to have at least one parameter; • All primary constructor parameters need to be marked as val or var; • Data classes cannot be abstract, open, sealed or inner;
$i") // prints "i = 10" val s = "abc" println("$s.length is ${s.length}") // prints "abc.length is 3" Type Check and Casts: if (obj is String) { print(obj.length) } fun demo(x: Any) { if (x is String) { print(x.length)//x is automatically cast to String } }