Q:

Kotlin program to check for Empty, Blank or NULL string

belongs to collection: Kotlin String Programs

0

Given a string, we have to check whether it is an empty, blank or NULL string.

Example:

    Input:
    str = ""

    Output:
    True

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to check for Empty, Blank or NULL string in Kotlin

package com.includehelp.basic

//Main Function, entry Point of Program
fun main(args: Array<String>) {
    ///Nullable String
    val s1: String?=null

    //Empty String
    val s2: String=""

    //Blank String, Contained only white spaces
    val s3="         "

    println("String s1 is  isNullOrEmpty :  ${s1.isNullOrEmpty()}")
    println("String s2 is  isEmpty       :  ${s2.isEmpty()}")
    println("String s3 is  isBlank       :  ${s3.isBlank()}")
}

Output

String s1 is  isNullOrEmpty :  true
String s2 is  isEmpty       :  true
String s3 is  isBlank       :  true

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin program to check whether a character is an ... >>
<< Kotlin program to find total number of vowels, con...