https://www.kancloud.cn/hanxt/javacrazy/1641322
```
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Employee {
private String name;
private int salary;
private String office;
}
```
```
import java.util.*;
import java.util.stream.Collectors;
public class ExampleEmployee {
private static List<Employee> employeeList = new ArrayList<>();
static{
employeeList.add(Employee.builder().name("Matt").salary(5000).office("New Work").build());
employeeList.add(Employee.builder().name("Steve").salary(6000).office("London").build());
employeeList.add(Employee.builder().name("Carrie").salary(3000).office("New Work").build());
employeeList.add(Employee.builder().name("Peter").salary(6000).office("London").build());
employeeList.add(Employee.builder().name("Pat").salary(7000).office("New Work").build());
employeeList.add(Employee.builder().name("Tammy").salary(27000).office("Shang Hai").build());
}
public static void main(String[] args) {
//anymatch
boolean isMatch=employeeList.stream().anyMatch(employee -> employee.getOffice().equals("London"));
System.out.println(isMatch);
boolean matched=employeeList.stream().allMatch(employee -> employee.getSalary()>2000);
System.out.println(matched);
//找出工资最高
Optional<Employee> hightSalary=employeeList.stream().max((e1,e2)->Integer.compare(e1.getSalary(),e2.getSalary()));
System.out.println(hightSalary);
//返回所有姓名列表
List<String> names=employeeList.stream().map(e->e.getName()).collect(Collectors.toList());
System.out.println(names);
//list 转化 map
Map<String,Employee> employeeMap =employeeList.stream().collect(Collectors.toMap((c->c.getName()),(value->value)));
employeeMap.forEach((key,value)-> System.out.println("key:"+key+"---value:"+value));
//统计办公室是new work的个数
long OfficeNum=employeeList.stream().filter(employee -> employee.getOffice()=="New Work").count();
System.out.println(OfficeNum);
//list 转化 set
Set<String> officeSet =employeeList.stream().map(employee -> employee.getOffice()).distinct().collect(Collectors.toSet());
System.out.println(officeSet);
//查找办公室在 new work的员工
Optional<Employee> allMatchedEmployee=employeeList.stream().filter(employee -> employee.getOffice().equals("New Work")).findAny();
System.out.println(allMatchedEmployee);
//根据工资升序列出员工列表
List<Employee> sortEmployeeList=employeeList.stream().sorted((e1,e2)->Integer.compare(e2.getSalary(),e1.getSalary())).collect(Collectors.toList());
System.out.println(sortEmployeeList);
//根据员工名字升序列出
List<Employee> sortEmployeeByName=employeeList.stream().sorted((e1,e2)->e1.getName().compareTo(e2.getName())).collect(Collectors.toList());
System.out.println(sortEmployeeByName);
//获取员工最高的前两条员工信息
List<Employee> Top2EmployeeList=employeeList.stream().sorted((e1,e2)->Integer.compare(e2.getSalary(),e1.getSalary())).limit(2).collect(Collectors.toList());
System.out.println(Top2EmployeeList);
//获取平均工资
OptionalDouble averageSalary=employeeList.stream().mapToInt(employee -> employee.getSalary()).average();
System.out.println(averageSalary);
//查找new york
OptionalDouble averageNewYork=employeeList.stream().filter(employee -> employee.getOffice().equals("New Work")).mapToInt(employee -> employee.getSalary()).average();
System.out.println(averageNewYork);
}
}
```
- 面试
- php
- laravel
- 安装
- 创建数据
- 创建控制器
- 错误
- 权限认证
- 图形验证码
- 管理员
- 无限分类
- 视频播放
- 推流
- pc页面
- thinkphp5
- 表单提交安全验证
- crontab
- 获取下级所有数据
- 过滤敏感词
- 二维码
- 邀请码
- jwt token
- 笛卡尔
- 高并发解决优化
- 设置多语言
- 计算经纬度两点距离
- 分片上传
- centos swoole
- 查看swoole版本
- centos 安装 redis
- 把整数随机分成n份或者红包
- 生成随机字符串
- 获取上级
- 宝塔搭建nginx推拉流
- 生成二维码海报
- 二维数组去重
- 经纬度 ---边距 和判断是不是范围内
- workerman
- 扩展
- redis
- mysql
- mysql 主从复制
- 定位问题语句
- 列的选择规则
- Enum介绍
- 索引介绍
- 延迟关联
- in 查询陷阱
- limit 优化
- 事务
- 读写分离
- mysql 权限错误
- mysql计算距离
- mysql数据导出导入
- 索引失效
- mysql 语句技巧
- linux
- 配置nginx 高可用
- Nginx内核参数优化
- 配置优化
- nginx-keepalived实现高可用负载
- lvs+keepalived
- centos5关闭防火墙
- nginx操作
- linux操作
- mysql 安装
- php
- 安装phpadmin
- php7安装mongodb
- 查看php位置
- 查找开启的进程端口
- 守护进程
- centos安装php7.2
- centos 错误解决
- 安装php7错误
- mysql 错误
- 支付宝支付
- html
- js 倒计时
- go vscode 配置
- go util
- 获取两个数之间随机数
- java
- lambda
- 随机抽取
- lombok
- springboot
- 常见注解
- 接受参数常用注解
- 文件上传
- 上传错误日志拦截
- 拦截器
- 定时任务
- mybatis
- 关联查询
- 全局配置
- 缓存
- git
- 微信相关
- 体现到零钱
- 服务商转账
- 公众号小程序相关
- 小程序二维码
- svn
- layui