突然发现Apache的StringUtils类的方法是真的好用,现在介绍一下他的方法吧
1.引入依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
2.看一下常见的方法吧
1)isEmpty
和isBlank
,来判断字符串是否为空的
两者的区别可以看https://www.cnblogs.com/dennisit/p/3705374.html
2)trim
去掉前后空格的
String str=" abcd ";
System.out.println(StringUtils.trim(str));
3)strip,去掉字符串两边的符号
String str = "[asdf,dsafjalsdfkj;ldkfj;sald]";
unit = StringUtils.strip(str, "[]");`
还有很多方法,自己去看源码吧