Skip to content

Instantly share code, notes, and snippets.

@zeraf29
Created March 23, 2022 12:28
Show Gist options
  • Save zeraf29/be46ec6601d539736ca7fa5828e75b4e to your computer and use it in GitHub Desktop.
Save zeraf29/be46ec6601d539736ca7fa5828e75b4e to your computer and use it in GitHub Desktop.
Coursera-kotlin extension function lexture
fun main(args: Array<String>) {
val s1: String? = null
val s2: String? = ""
s1.isEmptyOrNull() eq true
s2.isEmptyOrNull() eq true
val s3 = " "
s3.isEmptyOrNull() eq false
}
fun String?.isEmptyOrNull() = (this == null || this.isEmpty)
@zeraf29
Copy link
Author

zeraf29 commented Mar 23, 2022

isEmptyOrNull()

Add and implement an extension function 'isEmptyOrNull()' on the type String?. It should return true, if the string is null or empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment