Complete the code to declare a nullable String variable.
var name: String[1] = nullIn Kotlin, adding ? after a type makes it nullable, allowing it to hold null.
Complete the code to safely access the length of a nullable String.
val length = name[1].length!! which throws an exception if null.The safe call operator ?. allows accessing a property or method only if the object is not null.
Fix the error in the code to assign a nullable String to a non-nullable variable.
val nonNullName: String = name[1]?. which returns nullable type.?: "" which is for providing default values.The !! operator asserts that the value is not null and throws an exception if it is null.
Fill both blanks to create a map of words to their lengths only if length is greater than 3.
val lengths = mapOf([1] to [2]).filter { it.value > 3 }
The map pairs a word with its length. We use the word "hello" and its length.
Fill all three blanks to create a nullable variable, check if it is null, and provide a default value.
val input: String[1] = null val result = input [2] "default" println(result[3])
!! which throws exception if null.The variable is nullable with ?. The Elvis operator ?: provides a default if null. The safe call ?. accesses length safely.