commons-lang3工具类学习(二)
三、BooleanUtils
布尔工具类
and(boolean... array) 逻辑与
BooleanUtils.and(true, true) = true
BooleanUtils.and(false, false) = false
BooleanUtils.and(true, false) = false
BooleanUtils.and(true, true, false) = false
BooleanUtils.and(true, true, true) = true
compare(boolean x, boolean y) 比较两个布尔值并返回int类型 如果x == y返回0, !x && y 返回小于 0 ,x && !y 返回大于0
isFalse(Boolean bool) 是否是假并返回boolean
isTrue(Boolean bool) 是否是真并返回boolean
negate(Boolean bool) 逻辑非
BooleanUtils.negate(Boolean.TRUE) = Boolean.FALSE;
BooleanUtils.negate(Boolean.FALSE) = Boolean.TRUE;
BooleanUtils.negate(null) = null;
or(boolean... array) 逻辑或
BooleanUtils.or(true, true) = true
BooleanUtils.or(false, false) = false
BooleanUtils.or(true, false) = true
BooleanUtils.or(true, true, false) = true
BooleanUtils.or(true, true, true) = true
BooleanUtils.or(false, false, false) = false
toBoolean(Boolean bool) 将对象类型转换为基本数据类型并返回
BooleanUtils.toBoolean(Boolean.TRUE) = true
BooleanUtils.toBoolean(Boolean.FALSE) = false
BooleanUtils.toBoolean(null) = false
toBoolean(int value) 将int类型转换为boolean类型并返回
BooleanUtils.toBoolean(0) = false
BooleanUtils.toBoolean(1) = true
BooleanUtils.toBoolean(2) = true
toBoolean(String str) 将string类型转换为boolean类型并返回
BooleanUtils.toBoolean(null) = false
BooleanUtils.toBoolean("true") = true
BooleanUtils.toBoolean("TRUE") = true
BooleanUtils.toBoolean("tRUe") = true
BooleanUtils.toBoolean("on") = true
BooleanUtils.toBoolean("yes") = true
BooleanUtils.toBoolean("false") = false
BooleanUtils.toBoolean("x gti") = false
BooleanUtils.toBooleanObject("y") = true
BooleanUtils.toBooleanObject("n") = false
BooleanUtils.toBooleanObject("t") = true
BooleanUtils.toBooleanObject("f") = false
toInteger(boolean bool) 将boolean类型数据转换为int类型并返回
BooleanUtils.toInteger(true) = 1
BooleanUtils.toInteger(false) = 0
toStringOnOff(boolean bool) 将boolean类型数据转换为String类型'on' or 'off'并返回
BooleanUtils.toStringOnOff(true) = "on"
BooleanUtils.toStringOnOff(false) = "off"
toStringTrueFalse(Boolean bool) 将boolean类型数据转换为String类型''true' or 'false'并返回
BooleanUtils.toStringTrueFalse(true) = "true"
BooleanUtils.toStringTrueFalse(false) = "false"
toStringYesNo(boolean bool) 将boolean类型数据转换为String类型'yes' or 'no'并返回
BooleanUtils.toStringYesNo(true) = "yes"
BooleanUtils.toStringYesNo(false) = "no"
xor(boolean... array) 异或
BooleanUtils.xor(true, true) = false
BooleanUtils.xor(false, false) = false
BooleanUtils.xor(true, false) = true
四、ClassPathUtils
class路径工具
toFullyQualifiedName(Class<?> context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedName(StringUtils.class, "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"
toFullyQualifiedName(Package context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedName(StringUtils.class.getPackage(), "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"
toFullyQualifiedPath(Class<?> context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"
toFullyQualifiedPath(Package context, String resourceName) 返回一个由class包名+resourceName拼接的字符串
ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"
五、EnumUtils
枚举工具类
getEnum(Class<E> enumClass, String enumName) 通过类返回一个枚举,可能返回空
getEnumList(Class<E> enumClass) 通过类返回一个枚举集合
getEnumMap(Class<E> enumClass) 通过类返回一个枚举map
isValidEnum(Class<E> enumClass, String enumName) 验证enumName是否在枚举中,返回true false
demo
枚举类
public enum EnumDemo {AA("1"), BB("2");private String value;EnumDemo(String value) {this.value = value;}public String getValue() {return value;}
}测试
EnumDemo enumDemo = EnumUtils.getEnum(EnumDemo.class, "");
System.out.println(enumDemo);
System.out.println("-----");List<EnumDemo> list = EnumUtils.getEnumList(EnumDemo.class);
for (EnumDemo a : list) {System.out.println(a + ":" + a.getValue());
}
System.out.println("-----");Map<String, EnumDemo> enumMap = EnumUtils.
commons-lang3工具类学习(二)相关推荐
- Java中字符串工具类继承org.apache.commons.lang3.StringUtils类代码
场景 转换为字节数组:是否包含字符串:替换掉HTML标签方法:替换为手机识别的HTML,去掉样式及属性,保留回车: 缩略字符串(不区分中英文字符):转换为Double类型:转换为Float类型:转换为 ...
- hutool工具类生成二维码案例
hutool工具类生成二维码案例 一.环境: 添加hutool工具类依赖,hutool生成二维码是利用Google的zixing,而且不是强依赖,所以还需引入zxing依赖 <dependenc ...
- org.apache.commons.commons-lang3工具类(一)
https://blog.csdn.net/qq_31289187/article/details/85343068 本文只是简单的介绍了commons-lang3中的SystemUtils.Stri ...
- Apache Commons StringUtils工具类深入整理
字符串是在程序开发中最常见的,Apache Commons开源项目在org.apache.commons.lang3包下提供了StringUtils工具类,该类相当于是对jdk自带的String类的增 ...
- 常用工具类 (一) : Apache Commons 常用工具类整理 (全)
文章目录 一.commons-lang3 引入依赖 StringUtils 字符串工具类 StringEscapeUtils 转义字符串工具类 NumberUtils 数字工具类 ArrayUtils ...
- apache commons常用工具类
1.有些情况下,Arrays满足不到你对数组的操作?不要紧,ArrayUtils帮你 ArrayUtils public class TestMain { public static void ma ...
- java常用工具类_java(二):工作中常用到的工具类
工作中大家要用到很多工具类,第三方的jar中有很多现成的工具类符合自己的项目需要,这个时候就不需要去重复造轮子了,从而节省了很多时间,大家可以利用这些时间去做其它重要的事情,如果没有符合自己的工具类, ...
- commons-lang3工具类学习(一)
一.ArchUtils java运行环境的系统信息工具类 getArch();// 获取电脑处理器体系结构 32 bit.64 bit.unknown getType();// 返回处理器类型 x86 ...
- 水晶报表 jar包版本过低_工具类学习-UReport报表设计器整合
dada-report报表整合UReport报表设计器工具 结合日常工作和学习实践,针对传统报表子站面临的问题,尝试借助UReport报表设计器解决 1.可在现有工程基础上引入Ureport2报表设计 ...
最新文章
- 深度学习点云语义分割:CVPR2019论文阅读
- Oracle如何代码编辑,配置UltraEdit为Oracle PL/SQL代码编辑器
- 详解计算机视觉五大技术:图像分类、对象检测、目标跟踪、语义分割和实例分割
- [原] Unity调用android版新浪微博
- python北京时间代码_python代码定时同步本机的北京时间详解
- UOJ #164 【清华集训2015】V (线段树)
- 【最全最详细】publiccms实现将公共部分提取成单独模块引入
- java变量数据类型_java变量与数据类型
- mr InputFormat类
- 关于python文件打开模式表示错误的是_python文件读取失败了该怎么处理 !
- mysql数据库左连接
- 12款免费的桌面便签软件
- 联想台式主机拆机教程_联想一体机拆机图解 联想一体机电脑该怎么拆机
- 某度起诉“文库下载神器”,索赔300万
- Unity外接设备摇杆控制
- arcmap制作地闪密度专题图
- 【第一章 走进数据科学】袁博《数据挖掘:理论与算法》
- MATLAB R2021a 绘图函数fplot 使用详解
- 神经网络解决XOR(抑或)问题
- 强大的jqGrid!