Android TextUtils isEmpty vs String.isEmpty

前端 未结 5 919
南方客
南方客 2020-12-23 17:08

What is difference between TextUtils.isEmpty(string) and string.isEmpty?

Both do the same operation.

Is it advantageous to use

5条回答
  •  -上瘾入骨i
    2020-12-23 18:08

    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

提交回复
热议问题