让我们首先创建一个Stream:
Stream<String> stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming");
现在将上面的流转换为类型数组:
final String[] strArr = stream.toArray(String[]::new);
以下是在Java中将Stream转换为类型数组的示例:
import java.util.Arrays; 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[] strArr = stream.toArray(String[]::new); System.out.println("Array..."); Arrays.asList(strArr).forEach(n-> System.out.println(n)); } }
输出结果
Array... Bing Bang Theory Vampire Diaries Game of Thrones Homecoming