一,基本数据类型

八种基本类型有默认值

http://www.runoob.com/java/java-basic-datatypes.html

二,String 对象

// 判断String为空
//String s = "";
//String s = null;
String s = " ";
s = s.trim(); // 处理" "
// 方法1
if (s == null || "".equals(s)) { // null,""," "
System.out.println("String 为空1");
}
// 方法2
if (s == null || s.length() <= 0) { // 推荐 // null,""," "
System.out.println("String 为空2");
} else if (s.length() == 1 && Character.isWhitespace(s.charAt(0)) == true) {
System.out.println("String 为空5");
}
// 方法3
if (s == null || s.isEmpty()) { // null,""," "
System.out.println("String 为空3");
}
// 方法4
if (s == null || s == "") { // 不推荐 // null,""
System.out.println("String 为空4");
}

apache工具类

StringUtils.isBlank(s)

三,数组

// 判断数组为空
//String[] arr = null;
String[] arr = new String[0];
//String[] arr = new String[2]; // 有长度,不为空
if (arr == null || arr.length == 0) {
System.out.println("数组 为空1");
}

apache工具类

ArrayUtils.isEmpty(arr)

四,集合(List,Map,Set)

// 判断list为空(Map、Set同list)
//List<String> strList = null;
List<String> strList = new ArrayList<String>();
if (strList == null || strList.size() == 0) {
System.out.println("list 为空1");
}
if (strList == null || strList.isEmpty()) { // 推荐
System.out.println("list 为空2");
}

spring工具类

CollectionUtils.isEmpty(strList);

java 各种数据类型判断为空的更多相关文章

  1. Java中判断非空对象.

    Java中经常会遇到判断非空的时候. 有的时候判断了非空但是还是报空指针,为什么.? 判断的时候一般都会判断两次.类似于: Org o = new Org(); if ( o.getId()!=nul ...

  2. java中的不为空判断

    String不为空判断 if(null != str && !"".equals(str)) List不为空判断 if(list!=null && ...

  3. java的数据类型:基本数据类型和引用数据类型

    Java数据类型的基本概念 数据类型在计算机语言里面,是对内存位置的一个抽象表达方式,可以理解为针对内存的一种抽象的表达方式. 开始接触每种语言的时候,都会存在对数据类型的认识,有复杂的,有复杂的,各 ...

  4. Java 基本数据类型 及 == 与 equals 方法的区别

    Java数据类型分为基本数据类型与引用数据类型. 1 基本数据类型 byte:Java中最小的数据类型,在内存中占1个字节(8 bit),取值范围-128~127,默认值0 short:短整型,2个字 ...

  5. Java基本数据类型及其封装器的一些千丝万缕的纠葛

    一些概念     想必大家都知道Java的基础数据类型有:char.byte.short.int.long.float.double.boolean 这几种,与C/C++等语言不同的是,Java的基础 ...

  6. JAVA 变量 数据类型 运算符 知识小结

    ---------------------------------------------------> JAVA 变量 数据类型 运算符 知识小结 <------------------ ...

  7. 第十九节:Java基本数据类型,循环结构与分支循环

    基本数据类型 Java中的基本数据类型,有8种,在Java中有四种类型,8种基本数据类型. 字节 boolean 布尔型为1/8 byte 字节类型为1 short 短整型为2 char 字符型为2 ...

  8. golang interface判断为空nil

    要判断interface 空的问题,首先看下其底层实现. interface 底层结构 根据 interface 是否包含有 method,底层实现上用两种 struct 来表示:iface 和 ef ...

  9. Java 基本数据类型 && 位运算

    1. Java基本数据类型 1.1 数据类型示意图 类型 字节数 范围 byte 1 -128~127 short 2 -32768~32767 int 4 -231~231-1 long 8 -26 ...

随机推荐

  1. 转:Flutter Decoration背景设定(边框、圆角、阴影、形状、渐变、背景图像等)

    1 继续关系: BoxDecoration:实现边框.圆角.阴影.形状.渐变.背景图像 ShapeDecoration:实现四个边分别指定颜色和宽度.底部线.矩形边色.圆形边色.体育场(竖向椭圆).  ...

  2. vue-cli: 渲染过程理解(vue create demo01方式创建)

    1.根目录配置 vue.config.js, 设置入口文件: index.js module.exports = { pages:{ index: { entry: 'src/pages/home/i ...

  3. Spring Boot 构建电商基础秒杀项目 (一) 项目搭建

    SpringBoot构建电商基础秒杀项目 学习笔记 Spring Boot 其实不是什么新的框架,它默认配置了很多框架的使用方式,就像 maven 整合了所有的 jar 包, Spring Boot ...

  4. Redux学习(3) ----- 结合React使用

    Redux 和React 进行结合, 就是用React 做UI, 因为Redux中定义了state,并且定义了改变或获取state的方法,完全可以用来进行状态管理,React中就不用保存状态了,它只要 ...

  5. 数据库MySQL5.7.21win64位安装配置

    1,在MySQL官网下载mysql对应版本 https://dev.mysql.com/downloads/mysql/ 2,解压压缩文件到想要的位置 3,配置环境 打开  右键我的电脑-->属 ...

  6. HTML5-Input

    HTML5拥有多个新的表单输入类型,这些新特性提供了更好的输入控制和验证(有的浏览器不支持) color.date.datetime.datetime-local.email.month.number ...

  7. python 模块之-pickle

    Pickle的问题和所有其他编程语言特有的序列化问题一样,就是它只能用于Python,并且可能不同版本的Python彼此都不兼容,因此,只能用Pickle保存那些不重要的数据,不能成功地反序列化也没关 ...

  8. C# 动态调用泛型方法

    static void Main(string[] args) { #region 具体类型可传递. Personal specifiedPersonal = new Personal(); Empl ...

  9. 安卓Android基础第三天——数据库,ListView

    数据库介绍sqlite问:什么情况下使用数据库?答:有大量相似结构的数据需要存储的时候 数据库的创建定义一个类继承SqliteOpenHelpercontext:上下文name:数据库名字,如&quo ...

  10. Power Stations HDU - 3663

    我为什么T了.... Power Stations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...