字符串对象数组集合非空判断
生活随笔
收集整理的這篇文章主要介紹了
字符串对象数组集合非空判断
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
String 字符串
//直接用字符串調(diào)用方法 str.isEmpty() 如果為null則會拋出異常 if (StringUtils.isEmpty(str)){// "" 和null均判斷為空System.out.println("string為空"); }對象
//第1種:if (Objects.isNull(null)){ //nullSystem.out.println("obj為空");}//第2種:if (StringUtils.isEmpty(null)){System.out.println("obj為空");}數(shù)組
//數(shù)組需要判斷null和長度length(大小size) if (arr == null || arr.length == 0){System.out.println("arr為空"); }list set用法同list
//isEmpty()方法內(nèi)部就是判斷size大小 if (list.isEmpty() && list == null){ System.out.println("list為空"); } //使用spring提供的工具類List list=null;if (CollectionUtils.isEmpty(list)){System.out.println("list為空");}總結(jié)
以上是生活随笔為你收集整理的字符串对象数组集合非空判断的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Git 入门教程
- 下一篇: 解决 mysql>com.mysql.j