示例:
// 集合
List<String> orderNoList = new ArrayList<>();
orderNoList.add("111");
orderNoList.add("222");
orderNoList.add("333");
String result = StringUtils.join(orderNoList, "-");
System.out.println(result);
// 数组
String[] str = new String[]{"test","my"};
String resultStr = StringUtils.join(str, "-");
System.out.println(resultStr);
输出结果:
111-222-333
test-my
StringUtils.join用途:
将集合或数组以某拼接符拼接到一起形成新的字符串;
基本上此方法需传入2个参数,第一个参数是传入一个任意类型数组或集合,第二个参数是拼接符。
本文介绍了一种使用StringUtils.join方法高效拼接字符串的方法,该方法可以将集合或数组以指定符号连接成新的字符串,适用于多种应用场景。
1209

被折叠的 条评论
为什么被折叠?



