Stream流中的常用方法concat
package com.chunzhi.Test02Stream; import java.util.stream.Stream; /* Stream流中的常用方法concat:用于把流组合到一起 如果有两个流,希望合并成为一个流,那么可以使用Stream接口的静态方法concat static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b) */ public class Test08Stream_concat { public static void main(String[] args) { // 获取一个Stream流 String[] arr = {"迪丽热巴", "古力娜扎", "高圆圆", "吴彦祖", "彭于晏"}; Stream<String> stream = Stream.of(arr); // 获取Stream流 String[] arr01 = {"迪丽热巴", "古力娜扎", "高圆圆", "吴彦祖", "彭于晏"}; Stream<String> stream01 = Stream.of(arr); Stream<String> stream02 = Stream.concat(stream, stream01); // concat只能组合两个流 stream02.forEach(name -> System.out.println(name)); } }