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. 自定义注解_格式&本质和自定义注解_属性定义

    自定义注解: 格式: public @interface 注解名称{} 本质:注解本质上就是一个接口,该接口默认继承Annotation接口 public interface MyAnno exten ...

  2. git和提交分支

    实习到今天,已经开始做项目一段时间了,当然只是实习生的个人项目. 项目是导师发在git上面的,要求我们用git的PR提交 可是我不会啊...git仅仅是简单的个人提交总的项目到仓库里,什么新建分支,p ...

  3. 编译式安装MYSQL

    安装所需组件 实际上只需要这四个配置即可 升级boot开始 升级结束 重新执行cmake make && make install 启动mysql 发现启动失败 #####原因:这是由 ...

  4. (一)、数字图像处理(DIP)

    1.什么是图像? 图像是人类视觉的基础,是自然景物的客观事实,是人类认识世界和人类本身的重要源泉:也可以说图像是客观对象的一种表示. '图'是物体反射或透射光的分布:'像'是人的视觉系统所接受的图,在 ...

  5. Kotlin协程解析系列(上):协程调度与挂起

    vivo 互联网客户端团队- Ruan Wen 本文是Kotlin协程解析系列文章的开篇,主要介绍Kotlin协程的创建.协程调度与协程挂起相关的内容 一.协程引入 Kotlin 中引入 Corout ...

  6. ss 显示unix 域 的socket 缓冲区不正确

    一个unix 域socket,平时我们用ss -auxp 来查看是否有数据在内核没有到用户态, [root@localhost unix]# ss -auxp |grep -i server.o u_ ...

  7. mybatisplus-sql注入器

    sql注入器 使用mybatisplus只需要继承BaseMapper接口即可使用:但是有新的需求需要扩展BaseMapper里面的功能时可使用sql注入器. 扩展BaseMapper里面的功能 点击 ...

  8. 2020牛客NOIP赛前集训营-提高组(第二场)- B.包含 (FWT)

    题面 题解 这题就是个快速沃尔什变换的模板题,输入ai时,令s[ai]=1,对s[]做一遍DWT_AND(s)(快速沃尔什正变换,按位与),然后直接访问s[x]完事. #include<map& ...

  9. 【Java】学习路径58-TCP聊天-双向发送实现

    这一章内容比较复杂(乱) 重点在于解决利用TCP协议实现双向传输. 其余的细节(比如end)等,不需要太在意. 但是我也把折腾经历写出来了,如果大家和我遇到了类似的问题,下文可以提供一个参考. 目标: ...

  10. springboot配置(yami配置文件,JSR303数据校验,多环境配置)

    yami配置文件 YAML是 "YAML Ain't a Markup Language" (YAML不是一种标记语言)的递归缩写.在开发的这种语言时,YAML 的意思其实是:&q ...