What is difference between TextUtils.isEmpty(string)
and string.isEmpty
?
Both do the same operation.
Is it advantageous to use
TextUtils.isEmpty()
is better in Android SDK because of inner null check, so you don't need to check string for null before checking its emptiness yourself.
But with Kotlin, you can use String?.isEmpty()
and String?.isNotEmpty()
instead of TextUtils.isEmpty()
and !TextUtils.isEmpty()
, it will be more reader friendly
So I think it is preferred to use String?.isEmpty()
in Kotlin and TextUtils.isEmpty()
in Android Java SDK