Question - What is Elvis operator in Kotlin?
Answer -
In Kotlin, we can assign null values to a variable using the null safety property. To check if a value has null value, we can use if-else or can use the Elvis operator i.e. ?:
For example:
var name:String? = "Mindorks"
val namenameLength = name?.length ?: -1
println(nameLength)
In the above example, the Elvis operator(?:) we are using will return the length of the name if the value is not null; otherwise, if the value is null, then it will return -1.