zoukankan      html  css  js  c++  java
  • java / android int类型如何判空?

    /** 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 { }

    怎么判断ArrayList数组是否为空?


    如果判断其为nulll

    则为 list==null

    如果判断里面有没有元素..

    list.size()==0

    ArrayList<T> myList = new ArrayList<T>();
    
    // ArrayList 判空
    if (null != myList && myList.size > 0) {
        
    }

  • 相关阅读:
    eclipse 中 debug-config
    release稳定版本/snapshot快照版本
    nginx.config文件配置
    用 Spring Boot 和 MybatisPlus 快速构建项目
    github 生成ssh key
    Vagrant安装virtualbox
    修改linux默认时区
    《加密与解密》笔记
    manjaro 安装显卡驱动
    排序算法-C++实现
  • 原文地址:https://www.cnblogs.com/bluestorm/p/9370657.html
Copyright © 2011-2022 走看看