Post

KotlinKotlin

v
veerubhotla sowmithri

Posted on 19th April 2024|45 views

0
votes

Kotlin Null Check

How to null check in kotlin?

Answers
P
Lakshmi sowjanya

Posted on 19th April 2024

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<String>) { 

    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") 

    } 

}

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos