admin 管理员组

文章数量: 887021

61.stream流,limit,skip,concat,distinct

package com.itheima.streamdemo;import java.util.ArrayList;
import java.util.stream.Stream;public class MyStream4 {public static void main(String[] args) {ArrayList<String> list=new ArrayList<>();list.add("张三丰");list.add("张无忌");list.add("张翠山");list.add("王二麻子");list.add("张良");list.add("谢广坤");//list.stream().limit(2).forEach(s-> System.out.println(s));// list.stream().skip(2).forEach(s-> System.out.println(s));ArrayList<String> list2=new ArrayList<>();list2.add("张三丰");list2.add("张无忌");list2.add("张翠山");list2.add("王二麻子");list2.add("张良");list2.add("谢广坤");list2.add("谢广坤");list2.add("谢广坤");list2.add("谢广坤");/* Stream<String> stream1=list.stream();Stream<String> stream2= list2.stream();Stream<String> stream3 = Stream.concat(stream1, stream2);stream3.forEach(s-> System.out.println(s));*///Stream.concat(list.stream(),list2.stream()).forEach(s-> System.out.println(s));list2.stream().distinct().forEach(s-> System.out.println(s));}}

本文标签: 61stream流 limit skip concat distinct