1、Joiner-guava
//单个拼接
System.out.println(Joiner.on(",").join(1, 2));//1,2
//数组拼接
List<String> listStr = Arrays.asList("hello","java");
System.out.println(Joiner.on(",").join(listStr));//hello,java
List<Integer> list1 = Arrays.asList(1, 2, 5);
System.out.println(Joiner.on(",").join(list1));//1,2,5
2、String-java8
//单个拼接
System.out.println(String.join(",", "1", "2"));//1,2
//字符串数组
String []list ={"hello","java"};
System.out.println(String.join(",",list));//hello,java
3、StringUtils.join
最主要的功能是:将数组或集合以某拼接符拼接到一起形成新的字符串
String []list ={"hello","java"};
System.out.println(StringUtils.join(list,","));//hello,java
4、Stream流合并字符串、拼接字符串
List<String> strings = Arrays.asList("abc", "", "de", "efg", "abcd", "", "jkl");
String mergeString = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.joining(","));
System.err.println("合并字符串 : "+mergeString);