0

How to null check in kotlin?

Jun 16, 2020 in Kotlin by Veerubhotla

1 answers to this question.

0

The standard method of checking reference of null is by utilizing the if-else expression. We can explicitly check the null variable, also manage the two options independently.

Program for checking null conditions:

fun main(args: Array) { 

    var m: String? = "mindmajix"

    println(s) 

    if (m != null) { 

        println("length of the string ${m.length}") 

    } else { 

        println("it is a null string") 

    } 

    m = null

    println(m) 

    if (m != null) { 

        println("length of the string ${m.length}") 

    } else { 

        println("it is a null string") 

    } 

}

Jun 16, 2020 answered by Lakshmi

Related Questions

0 1 answers

Kotlin Lambda Example

Explain about kotlin lambda expression with example?

Jun 16, 2020 in Kotlin by Irshad
0 1 answers

Kotlin Abstract Class

What is the abstract class in kotlin?

Jun 16, 2020 in Kotlin by Irshad
0 1 answers

Kotlin Default Arguments

How the default argument in kotlin works?

Jun 16, 2020 in Kotlin by Irshad