java8的Collectors.joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
// 定义人名数组 String[] names = {"jordan", "kobe", "curry", "durant", "james"}; Stream<String> stream = Stream.of(names); // 拼接成 [x, y, z] 形式 String result1 = stream.collect(Collectors.joining(", ", "[", "]")); // 拼接成 x | y | z 形式 String result2 = stream.collect(Collectors.joining(" | ", "", "")); // 拼接成 (x -> y -> z) 形式 String result3 = stream.collect(Collectors.joining(" -> ", "(", ")"));