Complete the code to assign a default value using the Elvis operator.
val name: String? = null val displayName = name [1] "Unknown"
Complete the code to safely get the length of a nullable string or return 0 using the Elvis operator.
val text: String? = null val length = text?.length [1] 0
Fix the error in the code by completing the Elvis operator usage to provide a default value.
fun getUserName(user: User?): String {
return user?.name [1] "Guest"
}Fill both blanks to use the Elvis operator and safe call to get the length or return -1.
fun getLength(str: String?): Int {
return str[1]length [2] -1
}Fill all three blanks to chain safe calls and Elvis operators to get a nested property or default.
fun getCountry(user: User?): String {
return user[1]address[2]country [3] "Unknown"
}