Complete the code to safely access the length of the string variable.
val length = name[1]lengthThe safe call operator ?. allows accessing a property only if the object is not null, preventing null pointer exceptions.
Complete the code to safely call the function toUpperCase() on a nullable string.
val upper = text[1]toUpperCase()text is null.text is null.The safe call operator ?. calls the function only if text is not null, otherwise returns null.
Fix the error in the code by safely accessing the property length of a nullable string.
val len = nullableString[1]lengthThe safe call operator ?. avoids exceptions by returning null if nullableString is null.
Fill both blanks to safely call substring on a nullable string and provide a default empty string if null.
val result = nullableStr[1]substring(0, 3) [2] ""
Use ?. to safely call substring only if nullableStr is not null, and ?: to provide a default empty string if it is null.
Fill all three blanks to safely access the length of a nullable string's trimmed version, or return 0 if null.
val length = nullableStr[1]trim()[2]length [3] 0
length unnecessarily.First, safely call trim() with ?.. Then access length with a regular dot because trim() returns a non-null string. Finally, use ?: to return 0 if the whole expression is null.