Complete the code to declare a Kotlin variable with type inference.
val name = [1]In Kotlin, you can declare a variable with val and assign a value directly. Here, the value should be a string literal like "John".
Complete the code to create a Kotlin function that returns the length of a string.
fun lengthOfString(str: String): Int = str.[1]length() with parentheses (Java style)size which is for collectionscount which requires a predicateIn Kotlin, strings have a length property (unlike Java's length() method) that returns the number of characters.
Fix the error in the Kotlin code to safely access the length of a nullable string.
val length = str[1]length ?: 0
The safe call operator ?. allows accessing properties of a nullable object without throwing an error if it's null.
Fill both blanks to create a Kotlin data class with two properties.
data class User(val name: [1], val age: [2])
A Kotlin data class holds data. Here, name is a String and age is an Int.
Fill all three blanks to create a Kotlin map comprehension filtering entries with values greater than 10.
val filtered = mapOf("a" to 5, "b" to 15, "c" to 20).filter { it.[1] [2] [3] }
This code filters the map entries where the value is greater than 10.