Android TextUtils isEmpty与String.isEmpty [英] Android TextUtils isEmpty vs String.isEmpty

查看:192
本文介绍了Android TextUtils isEmpty与String.isEmpty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TextUtils.isEmpty(string) string.isEmpty 之间有什么区别?

两者都执行相同的操作.

Both do the same operation.

使用 TextUtils.isEmpty(string)是否有利?

推荐答案

是的,首选 TextUtils.isEmpty(string).

对于 string.isEmpty(),空字符串值将引发 NullPointerException

For string.isEmpty(), a null string value will throw a NullPointerException

TextUtils 将始终返回布尔值.

在代码中,前者只是

In code, the former simply calls the equivalent of the other, plus a null check.

return string == null || string.length() == 0;

这篇关于Android TextUtils isEmpty与String.isEmpty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆