StringUtils apache工具类小记
来源:互联网 发布:linux设置默认启动项 编辑:程序博客网 时间:2024/05/19 06:49
今天接触了StringUtils,这个apache的工具类,源码里有不少的方法用来方便大家 。最重要的是isEmpty和isBlank方法。下面的代码注解里写得很清楚了。
isEmpty()方法中, 判断逻辑就是这一句: return str == null || str.length() == 0;
当传入的参数str等于null ,或者它的长度为零时,那么isEmpty方法的返回值就是true,也就是说当传入的参数为空字符串或者null时,返回值为true。注释中提供了好几个例子,可以帮助大家理解。注意,whitespace在这个方法中返回false,意为notEmpty.
// Empty checks //----------------------------------------------------------------------- /** * <p>Checks if a String is empty ("") or null.</p> * * <pre> * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer trims the String. * That functionality is available in isBlank().</p> * * @param str the String to check, may be null * @return <code>true</code> if the String is empty or null */ public static boolean isEmpty(String str) { return str == null || str.length() == 0; }
isBlank方法测试的是是否是whitespace或者为 空字符串或者null.
/** * <p>Checks if a String is whitespace, empty ("") or null.</p> * * <pre> * StringUtils.isBlank(null) = true * StringUtils.isBlank("") = true * StringUtils.isBlank(" ") = true * StringUtils.isBlank("bob") = false * StringUtils.isBlank(" bob ") = false * </pre> * * @param str the String to check, may be null * @return <code>true</code> if the String is null, empty or whitespace * @since 2.0 */ public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; }
0 0
- StringUtils apache工具类小记
- Apache Common StringUtils工具类
- apache工具类之StringUtils(待续更新)
- 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
- 关于apache下的一个StringUtils工具类的介绍
- 工具类apache.commons.lang.StringUtils 使用心得
- 字符串工具类 org.apache.commons.lang.StringUtils
- org.apache.commons.lang3.StringUtils工具类常用方法
- 关于apache下的一个StringUtils工具类的介绍
- apache.commons.lang3.StringUtils工具类的使用
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- StringUtils工具类用法
- StringUtils工具类
- StringUtils工具类
- java最优有序查找——红黑树(RBT)算法
- [leetcode:python]58.Length of Last Word
- 第四章 分析论证结构
- ssh 的sessionFactory报错最不能原谅的是
- Linux 教程
- StringUtils apache工具类小记
- 判断某天为当年第几天的demo
- C/C++堆、栈及静态数据区详解
- 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数
- CODEVS1020 孪生蜘蛛
- 第七届蓝桥杯【国赛试题1】一步之遥
- 【bzoj1901】Zju2112 Dynamic Rankings
- 数据库优化——常用SQL优化
- Deep Learning(深度学习)学习笔记整理系列之(一)