package com.lovecoding.day24.stream01;

import com.lovecoding.day24.function02.Person;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Test02 {

    @Test
    public void test04(){
        String[] arr = {"hello","java"};

        Stream<String> stream = Arrays.stream(arr);

        stream.flatMap(  e -> Stream.of(e.split("|")) ).forEach(System.out::println);

    }

    @Test
    public void test03(){
        List<Person> people = List.of(new Person("zs"), new Person("ls"), new Person("ww"));

        people.stream().map( e -> e.getName() ).forEach(System.out::println);
    }

    @Test
    public void test02(){
        List<Person> people = List.of(new Person("zs"), new Person("ls"), new Person("ww"));
        //自然排序
        //people.stream().sorted().forEach(System.out::println);
        //定制
        people.stream().sorted( (e1 , e2 ) -> e1.getName().compareTo(e2.getName()) ).forEach(System.out::println);
    }

    @Test
    public void test01(){
        Stream<Integer> stringStream = Stream.of(1,2,3,4,5,6,7,8,1,2,3,4,11);

        //filter
        stringStream
                .filter( e -> e % 2 != 0 )
                .distinct()
                .skip(1)
                .limit(3)
                //.peek(System.out::println) //输出
                .forEach( e ->System.out.println());

    }
}
