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 ?: 0
The safe call operator ?. accesses a property only if the object is not null, otherwise returns null.
Fix the error in the code by choosing the correct operator to assert non-null.
val length = name[1].lengthThe non-null assertion operator !! tells Kotlin the value is not null and throws an exception if it is.
Fill both blanks to create a platform type variable and safely access its length.
val platformName: String[1] = getJavaString() val length = platformName[2].length ?: 0
Platform types come from Java and Kotlin treats them as non-null or nullable. We leave the type without '?' to indicate platform type. Use safe call ?. to access length safely.
Fill all three blanks to filter a list of platform type Strings for non-null values and get their lengths.
val javaList: List<String[1]> = getJavaList() val lengths = javaList.filterNotNull().map { it[2].length }.filter { it [3] 0 }
Platform types have no explicit nullability mark, so blank 1 is empty. Use !! to assert non-null inside map. Then filter lengths greater than zero.