首页 > 其他 > 详细

使用TextUtils.isEmpty简单化代码

时间:2016-10-08 18:54:23      阅读:206      评论:0      收藏:0      [点我收藏+]

如果让你判断一个文本框是否为空(null)或者没有任何值(length=0),你会怎么怎样去写代码,很多初学者可能会这样写:

if(text==null || text.length==0)

{........}

其实没有必要这么麻烦,在android的官方API中有更方便的解决方法:Returns true if the string is null or 0-length,可以使用这个方法-TextUtils.isEmpty()

可以这样写:

if(!TextUtils.isEmpty(text))

{.....}

使用TextUtils.isEmpty简单化代码

原文:http://www.cnblogs.com/peterpan-/p/5939628.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!