码迷,mamicode.com
首页 > 移动开发 > 详细

java / android int类型如何判空?

时间:2018-07-26 11:39:03      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:@param   code   ati   lan   封装   color   utils   数据   ext   

/** TextUtils.isEmpty() 方法的实现
* Returns true if the string is null or 0-length.
* @param str the string to be examined
* @return true if str is null or zero length
*/
    public static boolean isEmpty(@Nullable CharSequence str) {
        if (str == null || str.length() == 0)
            return true;
        else
            return false;
    }

int的默认值为0, Integer的默认值为null:

Java为每个原始类型提供了封装类,Integer是java为int提供的封装类。
int的默认值为0,而Integer的默认值为null,即Integer可以区分出未赋值和值为0的区别,int则无法表达出未赋值的情况,

 

简单android的int判空方法:

int myInt = getInt();
if (TextUtils.isEmpty(String.valueOf(myInt))) {

java的int 判空:

//先把int类型的数据转换成String类型,然后判断String类型的数据是否为空。 
int myInt = getInt(); // getInt()可能返回为空!
if (null == String.valueOf(myInt) && "".equals(String.valueOf(myInt)) {
    //TODO 
}
// org.apache.commons.lang.StringUtils  ~ android中默认无法引用此包!
if
( !StringUtils.isEmpty(String.valueOf(myInt) ) ) { } else { }

 

java / android int类型如何判空?

标签:@param   code   ati   lan   封装   color   utils   数据   ext   

原文地址:https://www.cnblogs.com/bluestorm/p/9370657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!