null in kotlin code example

Example 1: kotlin is null or empty

// If we do not care about the possibility of getting spaces only...
if (number.isNullOrEmpty()) {
    // alerts the user to fill in their number!
}

// when we need to block the user from inputting spaces only
if (name.isNullOrBlank()) {
    // alerts the user to fill in their name!
}

Example 2: !! in kotlin

//The not-null assertion operator
val l = b!!.length

Example 3: elvis operator kotlin example

val l = b?.length ?: -1

Tags:

Java Example