JDK8的流收集器Collectors.joining
支持灵活的参数配置,可以指定字符串连接时的分隔符,前缀和后缀,可选用。用于拼接字符串,更方便好用。
例:
final String
[] strs
= {"a", "b", "c"};
Stream
<String> stream
= Stream
.of(strs
);
String res1
= stream
.collect(Collectors
.joining(", ", "[", "]"));
String res2
= stream
.collect(Collectors
.joining(" | ", "", ""));
String res3
= stream
.collect(Collectors
.joining(" - ", "", ""));
转载请注明原文地址: https://lol.8miu.com/read-15518.html