话不多说,上代码 首先创建一个集合
ArrayList<String> list = new ArrayList<String>() {
{
this.add("a");
this.add("b");
this.add("c");
}
};
1.无参
String result1 = list.stream().collect(Collectors.joining());
System.out.println(result1);
2.有参
String result2 = list.stream().collect(Collectors.joining("\r\n"));
System.out.println(result2);
2.1有前后缀
String result3 = list.stream().collect(Collectors.joining("-", "[", "]"));
System.out.println(result3);