StringUtils常用方法

isNotBlank

String test = "";
System.out.println(StringUtils.isNotBlank(test));
输出:false

trimToNull

清除掉testString首尾的空白字符,如果字符串为空格,则返回Null。

String test = " ";
String test2 = "   a b  ";
System.out.println(StringUtils.trimToNull(test));
System.out.println(StringUtils.trimToNull(test2));
输出:
null
a b

split

使用函数: StringUtils.split(testString,splitChars,arrayLength)
函数介绍:splitChars中可以包含一系列的字符串来劈分testString,并可以设定得
到数组的长度.注意设定长度arrayLength和劈分字符串间有抵触关系,建议一般情况下
不要设定长度.

String input = "A b,c.d|e";
String input2 = "Pharmacy, basketball funky";
String[] array1 = StringUtils.split( input, " ,.|");
String[] array2 = StringUtils.split( input2, " ,", 2 );

System.out.println( ArrayUtils.toString( array1 ) );
System.out.println( ArrayUtils.toString( array2 ) );
输出:
{A,b,c,d,e}
{Pharmacy,basketball funky}

chomp

去除尾部的换行符

String input = "Hello\n";
System.out.println( StringUtils.chomp( input ));
String input2 = "Another test\r\n";
System.out.println( StringUtils.chomp( input2 ));

join

将数组以符号或其他字符串为间隔组成新的字符串。

 private static final String[] str = {"1","2","3","4"};
 String str2 = StringUtils.join(str, "|");
 System.out.println(str2);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值