stream中skip,limit联合使用实现分页功能

public class TestHashSet {
    public static void main(String[] args) {
        HashSet<Map<String, String>> set = new HashSet<>();
        Map<String, String> map1 = new HashMap<>();
        Map<String, String> map2 = new HashMap<>();
        Map<String, String> map3 = new HashMap<>();
        Map<String, String> map4 = new HashMap<>();
        map1.put("1","2");
        map2.put("2","3");
        map3.put("3","4");
        map4.put("4","5");
        set.add(map1);
        set.add(map2);
        set.add(map3);
        set.add(map4);
        System.out.println("set = " + set);
        Set<Map<String, String>> collect = set.stream().skip(3).limit(2).collect(Collectors.toSet());
        System.out.println("collect = " + collect);
    }
}

你可能感兴趣的:(stream中skip,limit联合使用实现分页功能)