让我们创建字符串Stream:
Stream<String> stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming");
转换上面的字符串流,并将它们与Collector结合在一起:
final String str = stream.collect(Collectors.joining(" "));
以下是将字符串Stream转换为连接它们的示例:
import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { Stream<String> stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming"); final String str = stream.collect(Collectors.joining(" ")); System.out.println("Join result...\n"+str); } }
输出结果
Join result... Bing Bang Theory Vampire Diaries Game of Thrones Homecoming