利用StringUtils工具类进行String为空的判断
利用工具类进行String类型数据的非空判断,让自己的项目代码变得更加的简洁明了。
判断某字符串是否为空,为空的标准是 str==
null
或 str.length()==
0
下面是 StringUtils 判断是否为空的示例:
StringUtils.isEmpty(
null
) =
true
StringUtils.isEmpty(
""
) =
true
StringUtils.isEmpty(
" "
) =
false
//注意在 StringUtils 中空格作非空处理
StringUtils.isEmpty(
" "
) =
false
StringUtils.isEmpty(
"bob"
) =
false
StringUtils.isEmpty(
" bob "
) =
false
2
.
public
static
boolean
isNotEmpty(String str)
判断某字符串是否非空,等于 !isEmpty(String str)
下面是示例:
StringUtils.isNotEmpty(
null
) =
false
StringUtils.isNotEmpty(
""
) =
false
StringUtils.isNotEmpty(
" "
) =
true
StringUtils.isNotEmpty(
" "
) =
true
StringUtils.isNotEmpty(
"bob"
) =
true
StringUtils.isNotEmpty(
" bob "
) =
true
3
.
public
static
boolean
isBlank(String str)
判断某字符串是否为空或长度为
0
或由空白符(whitespace) 构成
下面是示例:
StringUtils.isBlank(
null
) =
true
StringUtils.isBlank(
""
) =
true
StringUtils.isBlank(
" "
) =
true
StringUtils.isBlank(
" "
) =
true
StringUtils.isBlank(
"\t \n \f \r"
) =
true
//对于制表符、换行符、换页符和回车符
StringUtils.isBlank()
//均识为空白符
StringUtils.isBlank(
"\b"
) =
false
//"\b"为单词边界符
StringUtils.isBlank(
"bob"
) =
false
StringUtils.isBlank(
" bob "
) =
false
4
.
public
static
boolean
isNotBlank(String str)
判断某字符串是否不为空且长度不为
0
且不由空白符(whitespace) 构成,等于 !isBlank(String str)
下面是示例:
StringUtils.isNotBlank(
null
) =
false
StringUtils.isNotBlank(
""
) =
false
StringUtils.isNotBlank(
" "
) =
false
StringUtils.isNotBlank(
" "
) =
false
StringUtils.isNotBlank(
"\t \n \f \r"
) =
false
StringUtils.isNotBlank(
"\b"
) =
true
StringUtils.isNotBlank(
"bob"
) =
true
StringUtils.isNotBlank(
" bob "
) =
true
转载于:https://www.cnblogs.com/mr-wuxiansheng/p/7500487.html
利用StringUtils工具类进行String为空的判断相关推荐
- StringUtils 工具类常用方法汇总 1(判空、转换、移除、替换、反转)
Apache commons lang3 包下的 StringUtils 工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常方便.最近自己也经常在项目中使用到了里面的一些方法,在这里将常用的 ...
- Apache Commons包 StringUtils工具类深入整理(转载)
[转载地址]:cnblogs.com/sealy321/p/10227131.html 字符串是在程序开发中最常见的,Apache Commons开源项目在org.apache.commons.lan ...
- Apache Commons StringUtils工具类深入整理
字符串是在程序开发中最常见的,Apache Commons开源项目在org.apache.commons.lang3包下提供了StringUtils工具类,该类相当于是对jdk自带的String类的增 ...
- 学习StringUtils工具类
在JAVA中我们用的最多的类应该就是String了.对于String的处理说简单也简单,但是有的时候要自己去实现一些功能还是要浪费一点时间的.一年之前接触了StringUtils这个工具类,就猛然爱上 ...
- Apache commons lang3 StringUtils工具类
Apache commons lang3 StringUtils工具类 Apache commons lang3包下的StringUtils工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常 ...
- 利用hutool工具类导出Excel
简单介绍 可以使用hutool工具类,简单的生成Excel.本质上还是使用的POI组件,只是对其进行了封装,避免开发人员重复造轮子 hutool工具类链接 maven导入 <!-- hutool ...
- StringUtils工具类说明
/***************************************为空判断***************************************///null 和 "& ...
- common-lang的StringUtils工具类说明
null 和 ""操作 判断是否Null 或者 "" System.out.println(StringUtils.isEmpty(null)); System ...
- StringUtils工具类常用方法
StringUtils类在操作字符串是安全的,不会报空指针异常,也正因此,在操作字符串时使用StringUtils相比使用原生的String会更加安全. 一.判空 StringUtils提供常用的判断 ...
最新文章
- C#线程间操作无效: 从不是创建控件 XX 的线程访问它
- 2015 AlBaath Collegiate Programming Contest(2月14日训练赛)
- Linux Shell编程入门
- div禁用,不可点击
- 〈转〉用VS2005.NET进行三层结构应用程序的开发
- 网络——Base64Encode(转:自定义Base64编码器——Base64Encode)
- getParameter
- jfinal项目tomcat下部署
- discuz点歌台插件
- ELK快速搭建日志平台(基于7.9.3)
- 【优化算法】混合蛙跳算法(SLFA)【含Matlab源码 300期】
- devc运行窗口不显示_编写Qt多窗口程序
- SpringBoot 实现SQL脚本自动执行
- [附源码]java毕业设计卡通动漫商城系统
- 动态规划处理长方形分割为正方形问题
- 微信收到消息很慢无法连接服务器,微信消息总是延迟接收怎么办?
- 手机企业微信下载文件存储地址
- 解决remote: You are not allowed to upload code.fatal: unable to access.The requested URL error:403
- C 喵帕斯之平地摔 SDUT
- 沟通技巧-《好好说话》书中的精髓:掌握沟通、说服、谈判、演讲、辩论的五维话术,让你在任何场景下,都能做到处变不惊,学会说话这个技术活。
热门文章
- Javascript常用正则表达式汇总
- Go语言Web框架gwk介绍 (四)
- python中利用itchat实现自动回复
- 二叉搜索树的第k个节点
- 动态RAM的集中刷新、分散刷新、异步刷新
- delphi 监控文件变化_监控Linux文件变化,防止系统被黑
- Python接口自动化-接口基础(一)
- Failed to parse PID from file /run/nginx.pid: Invalid argument
- Mac上的IDEA安装配置maven
- 北岛创投发起7200万美元加密VC基金,保罗·都铎·琼斯参与投资