实用的 集合工具类 和 String工具类
来源:互联网 发布:gson map to json 编辑:程序博客网 时间:2024/05/31 13:17
集合工具类:CollectionUtil
method:
1.isNotEmpty() 不为空
2.isEmpty() 为空
举例:map集合
Map<String,String> mapA= new HashMap<>();
Map<String,String> mapB= new HashMap<>();
Map<String,String> mapC= new HashMap<>();
mapA.put("1", "1");
mapB.put(null, null);
System.out.println(CollectionUtil.isNotEmpty(mapA));//true
System.out.println(CollectionUtil.isNotEmpty(mapB));//true
System.out.println(CollectionUtil.isNotEmpty(mapC));//false
Map<String,String> mapB= new HashMap<>();
Map<String,String> mapC= new HashMap<>();
mapA.put("1", "1");
mapB.put(null, null);
System.out.println(CollectionUtil.isNotEmpty(mapA));//true
System.out.println(CollectionUtil.isNotEmpty(mapB));//true
System.out.println(CollectionUtil.isNotEmpty(mapC));//false
String工具类:StringUtil
method:
1.isNotBlank
2.isBlank
String sA= null;
String sB= "";
String sC= "123";
System.out.println(StringUtil.isNotBlank(sB));//false
System.out.println(StringUtil.isNotBlank(sA));//false
System.out.println(StringUtil.isNotBlank(sC));//true
String sB= "";
String sC= "123";
System.out.println(StringUtil.isNotBlank(sB));//false
System.out.println(StringUtil.isNotBlank(sA));//false
System.out.println(StringUtil.isNotBlank(sC));//true
3.alignRight("str", *) 扩展并右对齐字符串,用空格' '
填充左边(*为数字类型,可以为负数,表示消除空格数量)
4.alignLeft("str", *) 扩展并右对齐字符串,用空格' '填充左边 (*为数字类型,可以为负数,表示消除空格数量)
5.center("str",*) 用空格' '填充两边。
6.capitalize("str") 将字符串的首字符转成大写(Character.toTitleCase),其它字符不变。
7.chomp("str","separator") 删除字符串末尾的指定字符串。如果字符串不以该字符串结尾,则什么也不做。
8.containsOnly("str","valid") 检查字符串是是否只包含指定字符集合中的字符。但是空字符串永远返回true.
9.containsNone("str", "valid") 检查字符串是是否不包含指定字符集合中的字符。 但是空字符串永远返回true.
10.equals(): 比较两个字符串是否相等,如果两个均为null,则也认为相等
StringUtils.equals("", ""); //true
StringUtils.equals(null, null); //true
StringUtils.equals(null, ""); //false
StringUtils.equals("",null); //false
StringUtils.equals(null,""); //false
StringUtils.equalsIgnoreCase("ss", "Ss"); //不区分大小写--true
0 0
- 实用的 集合工具类 和 String工具类
- T类最实用的网站及工具大集合
- 最实用的IT类网站及工具大集合
- RxTools一款强大实用的工具类集合
- 分享一个实用的String的工具类
- 实用的Http工具类
- 实用的JSON工具类
- 实用的工具类Logutil
- StringUtil String工具类常用方法集合
- 日期和String类型的工具类
- 集合工具类和排序
- 实用的30款JS类库和工具
- 实用Map工具类
- 集合框架的工具类
- 集合框架的工具类
- java__集合的工具类
- 集合框架的工具类
- 绝对干货!IT类最实用的网站及工具大集合!
- OpenCV: Mat
- 论fork()函数与Linux中的多线程编程
- 安卓四大组件之一Activity的生命周期
- 选择排序法C#实现
- 并查集——分身法
- 实用的 集合工具类 和 String工具类
- 黑白夜间切换
- selenium版本下载
- 怎么在微信上实现瑜伽在线预约功能
- 图像预处理——边界检测
- UML——初识
- 167. Two Sum II
- 第21章 信号频谱分析
- Activity生命周期笔记