6 List跳过指定条数--skip

版权声明:看什么?6,你和我,走一波! https://blog.csdn.net/qq_31323797/article/details/89333386
package com.java8.list;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author gp6
 * @date 2019-04-15
 */
public class TestList {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<Person>() {{
            add(new Person(1, "小明", 11, 1));
            add(new Person(2, "小红", 12, 0));
            add(new Person(3, "小兰", 13, 0));
            add(new Person(4, "小强", 14, 0));
            add(new Person(5, "小咪", 10, 1));
            add(new Person(6, "小子", 11, 1));
            add(new Person(7, "小虾", 12, 1));
            add(new Person(7, "小哈", 12, 1));
        }};


         // 先取出性别为0的列表,在跳过指定条数,取出后面的列表
        List<Person> personSkipSort = personList.stream()
                .filter(person -> person.getSex().equals(0))
                .skip(2)
                .collect(Collectors.toList());

        // [Person(id=4, name=小强, age=14, sex=0)]
        System.out.println(personSkipSort);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_31323797/article/details/89333386
0条评论
添加一条新回复