Stream流09_Stream流中的常用方法_concat

Stream流09_Stream流中的常用方法_concat

package com.itheima.demo02.Stream;

import java.util.stream.Stream;

/*

Stream流中的常用方法_concat:用于把流组合到一起
如果有两个流,希望合并成为一个流,那么可以使用Stream接口的静态方法concat
static  Stream concat(Stream a, Stream b)

*/
public class Demo08Stream_concat {

public static void main(String[] args) {
    //创建一个Stream流
    Stream stream1 = Stream.of("张三丰", "张翠山", "赵敏", "周芷若", "张无忌");
    //获取一个Stream流
    String[] arr = {"美羊羊","喜洋洋","懒洋洋","灰太狼","红太狼"};
    Stream stream2 = Stream.of(arr);
    //把以上两个流组合为一个流
    Stream concat = Stream.concat(stream1, stream2);
    //遍历concat流
    concat.forEach(name-> System.out.println(name));
}

}

你可能感兴趣的:(java)