import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors; public class Main { public static void main(String[] args) { List<Student> studentList = new ArrayList<>(); studentList.add(new Student(1,2,1000,88));
studentList.add(new Student(2,2,1000,76));
studentList.add(new Student(3,1,2000,79));
studentList.add(new Student(4,2,3000,88));
studentList.add(new Student(5,2,3000,49));
studentList.add(new Student(5,1,4000,69));
studentList.add(new Student(5,1,4000,96));
// 按照班级分组,性别为女,分数降序 Map<String, List<Student>> groupList = new HashMap<String, List<Student>>(); studentList.stream().filter(student ->
student.getSex() == 2
).collect(Collectors.groupingBy(Student::getClassNo,
Collectors.toList())).forEach(
(classNo, listByClassNo) -> {
groupList.put(classNo + "",
listByClassNo.stream().sorted(Comparator.comparing(Student::getScore).reversed()).collect(Collectors.toList()));
} ); System.out.println("Hello World!");
} private static class Student implements Serializable { private int id; private int sex; private int classNo; private int score; public Student(int id, int sex, int classNo, int score) { this.id = id; this.sex = sex; this.classNo = classNo; this.score = score; } public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public int getSex() {
return sex;
} public void setSex(int sex) {
this.sex = sex;
} public int getClassNo() {
return classNo;
} public void setClassNo(int classNo) {
this.classNo = classNo;
} public int getScore() {
return score;
} public void setScore(int score) {
this.score = score;
}
} }

关于JDK8中stream的用法小总结。的更多相关文章

  1. JDK8中Stream使用解析

    JDK8中Stream使用解析 现在谈及JDK8的新特新,已经说不上新了.本篇介绍的就是Stream和Lambda,说的Stream可不是JDK中的IO流,这里的Stream指的是处理集合的抽象概念『 ...

  2. Jdk8中Stream流的使用,让你脱离for循环

    学习要求: 知道一点儿函数式接口和Lambda表达式的基础知识,有利于更好的学习. 1.先体验一下Stream的好处 需求:给你一个ArrayList用来保存学生的成绩,让你打印出其中大于60的成绩. ...

  3. jdk8中的stream

    https://www.ibm.com/developerworks/cn/java/j-lo-java8streamapi/ Java 8 中的 Streams API 详解 Streams 的背景 ...

  4. forEach与jdk8中的lambda, Stream

    增强for循环 :forEach 反编译后可以看到实际使用的仍然是Iterator+while遍历的 forEach的优点是写法简单,缺点是不能使用xxx.remove(e)或者iter.remove ...

  5. java stream中Collectors的用法

    目录 简介 Collectors.toList() Collectors.toSet() Collectors.toCollection() Collectors.toMap() Collectors ...

  6. 【JDK8】JDK 8 中Stream流中的去重的方法

    JDK 8 中Stream流中去重的方法 1.简单的去重,可以使用distinct()方法去重,该方法是通过比较equals和hashcode值去去重, 2.复杂的去重, 例如,在一个JavaBean ...

  7. 13万字详细分析JDK中Stream的实现原理

    前提 Stream是JDK1.8中首次引入的,距今已经过去了接近8年时间(JDK1.8正式版是2013年底发布的).Stream的引入一方面极大地简化了某些开发场景,另一方面也可能降低了编码的可读性( ...

  8. Linux中find常见用法

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  9. [转]Linux中find常见用法示例

    Linux中find常见用法示例[转]·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \;find命令的参 ...

随机推荐

  1. Nmap 操作手册 - 完整版

    目录 Nmap - 基础篇 Nmap 安装 RedHat Windows Debina & Ubuntu Others Linux Nmap 参数(简单版) 目标说明 主机发现 扫描技术 端口 ...

  2. 使用Docker-compose来封装celery4.1+rabbitmq3.7服务,实现微服务架构

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_115 大家都知道,Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统,在之前的一篇文章中:python3.7+Torn ...

  3. Python算法之动态规划(Dynamic Programming)解析:二维矩阵中的醉汉(魔改版leetcode出界的路径数)

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_168 现在很多互联网企业学聪明了,知道应聘者有目的性的刷Leetcode原题,用来应付算法题面试,所以开始对这些题进行" ...

  4. Nginx 集群部署(Keepalived)

    # Nginx集群部署 # 当我们的用户同时访问量达到一定量的时候,一台服务器是不够用的 # 这个时候我们需要解决这个问题肯定是要添加新的服务器去处理用户访问 # 多台服务器处理用户访问就需要我们集群 ...

  5. Spring 请求方法的调用原理(Controller)和请求参数的获取的原理

    1.请求映射原理 所有的请求都会经过DispatcherServlet这个类,先了解它的继承树 本质还是httpServlet 原理图 测试 request请求携带的参数 ​ 从requestMapp ...

  6. Hammersley采样类定义和测试

    原理参照书籍 类声明: #pragma once #ifndef __HAMMERSLEY_HEADER__ #define __HAMMERSLEY_HEADER__ #include " ...

  7. Floyd算法详解

    Floyd本质上使用了DP思想,我们定义\(d[k][x][y]\)为允许经过前k个节点时,节点x与节点y之间的最短路径长度,显然初始值应该为\(d[k][x][y] = +\infin (k, x, ...

  8. 活动报名|对话贡献者:DolphinScheduler x Pulsar 在线 Meetup

    各位 DolphinScheduler 和 Pulsar 社区的小伙伴们,Apache DolphinScheduler x Pulsar 在线 Meetup 来啦! 导语 大数据任务调度.消息流的订 ...

  9. Luogu3855 [TJOI2008]Binary Land (BFS)

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  10. WPF中使用System.Windows.Interactivity实现事件绑定的替代方法

    一.问题描述 对于 Button 等控件,在 MVVM 中我们能通过 Command 绑定解决 Click 事件.具体如下所示: <Button Margin="10" He ...