Profile
September 5, 2022

How to use Elvis Operator with Let in Kotlin

Elvis Operator with Let is a most frequently used operator which is denoted by “?:”, its appropriate use is when an object is declared nullable.

 

 

How to use Elvis Operator "?:"

 

object ? :  "return something if object is null”

Example:

var abc: String? = null
print(abc?:"hello world")
//output: hello world

 

Use Elvis Operator with Let:

 var str: String? = null
 str?.let { 
   // this block will beexecutedd when str is not null
 }?:{
  // do something when str is null
 }

 

Checkout Our Latest Tools

 

APK Decompiler

Java Decompiler

Email Validator

APK Downloader

Last edited on September 5, 2022 by Admin

Latest articles