package test;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Test11 {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1,2,3,4,5,6,7,8,9,10,8);
Integer count2 = list.stream()
.reduce(0, (x, y) -> x + y);
System.out.println(count2);
System.out.println();
list.stream().filter(x -> x>5).limit(3).forEach(System.out::println);
System.out.println();
list.stream().filter(x -> x>5).skip(1).forEach(System.out::println);
System.out.println();
list.stream().distinct().forEach(System.out::println);
System.out.println();
List<Person> personList = Arrays.asList(new Person("张三","18"),new Person("李四","19"),new Person("王五","15"),new Person("刘六","18"));
personList.stream().map(person -> person.getName()).forEach(System.out::println);
System.out.println();
personList.stream().sorted((person1,person2) -> {
if(person1.getAge().equals(person2.getAge())){
return person1.getName().compareTo(person2.getName());
}else{
return person1.getAge().compareTo(person2.getAge());
}
}).forEach(System.out::println);
System.out.println();
personList.stream().map(Person :: getAge).collect(Collectors.toList()).forEach(System.out::println);
}
}