Kotlin: using elvis operator

Example:

val name: String? = null
The Elvis operator provides a shorthand to handle nullable types.

Solution:

val length = name?.length ?: 0

Beginner's Guide to Kotlin