Map.Entry与entrySet与entry,getKey()与entry.getValue()的用法
直接上代码 实体类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SinglePressureResultDTO {private Integer Times; private Integer SCU_number; private Boolean Intervention; private Long startTime_low; private Long low_time; private Long startTime_rise; private Long endTime_rise; private Long rise_time; private Long total_time; private Long endTime_resistance; private Long resistance_time; private Long time_resistance_turningup; private Float pressure_resistance_turningup; private Float end_resistance; private Float initial_support;private Float moving_pressure;
}
测试
public static void main(String[] args) {//给集合赋值 元素为SinglePressureResultDTO对象List<SinglePressureResultDTO> singlePressure=new ArrayList<>();singlePressure.add(new SinglePressureResultDTO(1,2,true,1l,1l,1l,1l,1l,1l,1l,1l,1l,1f,1f,1f,1f));singlePressure.add(new SinglePressureResultDTO(1,3,true,1l,1l,1l,1l,1l,1l,1l,1l,1l,1f,1f,1f,1f)); singlePressure.add(new SinglePressureResultDTO(1,4,true,2l,1l,1l,1l,1l,1l,1l,1l,1l,1f,1f,1f,1f));singlePressure.add(new SinglePressureResultDTO(1,4,false,3l,1l,1l,1l,1l,1l,1l,1l,1l,1f,1f,1f,1f));System.out.println(adapterToASQTotalDTO(singlePressure)+" )))");public static ASQTotalDTO adapterToASQTotalDTO(List<SinglePressureResultDTO> singlePressure) {ASQTotalDTO asqTotalDTO = new ASQTotalDTO();List<ASQSingleDTO> asqs = new ArrayList<>();if (CollectionUtil.isEmpty(singlePressure)) {return asqTotalDTO;}//将传递过来的集合以SCU_number属性进行分组 类似于key-value的形式 //key是SCU_number,value是SCU_number符合条件的所有对象(集合)//{2=[SinglePressureResultDTO(Times=1, SCU_number=2, Intervention=true, startTime_low=1, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0)],// 3=[SinglePressureResultDTO(Times=1, SCU_number=3, Intervention=true, startTime_low=1, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0)],// 4=[SinglePressureResultDTO(Times=1, SCU_number=4, Intervention=true, startTime_low=2, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0), SinglePressureResultDTO(Times=1, SCU_number=4, Intervention=false, startTime_low=3, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0)]} Map<Integer, List<SinglePressureResultDTO>> scuResult = singlePressure.stream().collect(Collectors.groupingBy(SinglePressureResultDTO::getSCU_number));System.out.println(scuResult+" scuResult");//获取每一个集合中的元素 确切来说,获取每一个key-value//并且遍历每一个key-valuefor (Map.Entry<Integer, List<SinglePressureResultDTO>> entry : scuResult.entrySet()) {//在这里可以打印每一个key-valueSystem.out.println(entry+" key-value");ASQSingleDTO asqSingle = new ASQSingleDTO();List<ASQCirculateDTO> auto = new ArrayList<>();List<ASQCirculateDTO> manual = new ArrayList<>();//遍历每一个key-value中的value(注意 value是集合)for (SinglePressureResultDTO pressure : entry.getValue()) {//同样可以获取到entry中的key以及entry中的valueSystem.out.println(entry.getKey()+" **&^&%^");System.out.println(entry.getValue()+" *&^%");ASQCirculateDTO dto = new ASQCirculateDTO();dto.setDownStartTime(pressure.getStartTime_low());dto.setDownEndTime(pressure.getStartTime_rise());dto.setUpStartTime(pressure.getStartTime_rise());dto.setUpEndTime(pressure.getEndTime_rise());dto.setEndStrength(pressure.getEnd_resistance());dto.setInflectionPressure(pressure.getPressure_resistance_turningup());dto.setInitStrength(pressure.getInitial_support());if (pressure.getIntervention()) {manual.add(dto);} else {auto.add(dto);}}asqSingle.setScuNo(entry.getKey());System.out.println(entry.getKey()+" entry.getKey()");asqSingle.setAsqNum(auto.size());asqSingle.setNsqNum(manual.size());asqSingle.setAuto(auto);asqSingle.setManual(manual);//每个支架数据作为asqs的一个元素asqs.add(asqSingle);}asqTotalDTO.setAsqs(asqs);System.out.println(asqTotalDTO);List<ASQSingleDTO> asqs1 = asqTotalDTO.getAsqs();//for (ASQSingleDTO asqSingleDTO:asqs1) {//System.out.println(asqSingleDTO+" -----");//}System.out.println(asqs1+" asq1");return asqTotalDTO;}}
运行 System.out.println(asqs1+" asq1");结果
[ASQSingleDTO{scuNo=2, asqNum=0, nsqNum=1, auto=[], manual=[ASQCirculateDTO{downStartTime=1, downEndTime=1, moveStartTime=null, moveEndTime=null, upStartTime=1, upEndTime=1, inflectionPressure=1.0, initStrength=1.0, endStrength=1.0}]},
ASQSingleDTO{scuNo=3, asqNum=0, nsqNum=1, auto=[], manual=[ASQCirculateDTO{downStartTime=1, downEndTime=1, moveStartTime=null, moveEndTime=null, upStartTime=1, upEndTime=1, inflectionPressure=1.0, initStrength=1.0, endStrength=1.0}]},
ASQSingleDTO{scuNo=4, asqNum=1, nsqNum=1, auto=[ASQCirculateDTO{downStartTime=3, downEndTime=1, moveStartTime=null, moveEndTime=null, upStartTime=1, upEndTime=1, inflectionPressure=1.0, initStrength=1.0, endStrength=1.0}], manual=[ASQCirculateDTO{downStartTime=2, downEndTime=1, moveStartTime=null, moveEndTime=null, upStartTime=1, upEndTime=1, inflectionPressure=1.0, initStrength=1.0, endStrength=1.0}]}] asq1
打印key-value运行结果
2=[SinglePressureResultDTO(Times=1, SCU_number=2, Intervention=true, startTime_low=1, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0)] key-value
3=[SinglePressureResultDTO(Times=1, SCU_number=3, Intervention=true, startTime_low=1, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0)] key-value
4=[SinglePressureResultDTO(Times=1, SCU_number=4, Intervention=true, startTime_low=2, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0), SinglePressureResultDTO(Times=1, SCU_number=4, Intervention=false, startTime_low=3, low_time=1, startTime_rise=1, endTime_rise=1, rise_time=1, total_time=1, endTime_resistance=1, resistance_time=1, time_resistance_turningup=1, pressure_resistance_turningup=1.0, end_resistance=1.0, initial_support=1.0, moving_pressure=1.0)] key-value
这辈子坚持与不坚持都不可怕,怕的是独自走在坚持的道路上!!! 欢迎加入技术群聊。
Map.Entry与entrySet与entry,getKey()与entry.getValue()的用法相关推荐
- for(Map.EntryString, String entry:params.entrySet())
for(Map.Entry<String, String> entry:params.entrySet()) 意思是:把params中的,每一个元素放入map中.
- 遍历Map keySet和entrySet
public class test {public static void main(String[] args) {Map<String, String> map = new HashM ...
- 微信小程序:map组件的简单使用,标注callout与label简单用法
效果图 wxml <mapid="myMap"style="width: 100%; height: 30 ...
- Android中List、Set、Map数据结构详解
Android中一般使用的数据结构有java中的基础数据结构List,Set,Map.还有一些Android中特有的几个,SparseArray(使用Map时Key是int类型的时候可以用这个代替)等 ...
- poi操作word docx文档内容替换详解
WORD文档文字替换 利用关键字下角标位置的方式处理word文档区域文字分割无法匹配的问题 /*** DOCX文档字符串查找** @param document 文档* @param str 查找字符 ...
- Map json数据解析
个人学习资源免费分享网站:http://xiaocaoshare.com/ public class App { public static void main(String[] args) ...
- 关于Map迭代循环,key和value的顺序问题
使用Hashtable,keySet()返回的顺序为降序(key降顺序) ---->6, 5, 4, 3, 2, 1 使用TreeMap,keySet()返回的顺序为升序(key升顺序) --- ...
- Map、HashMap、TreeMap、LinkedHashMap
Map 与Set接口一样,Map也是一个接口不能实例化 Map是一种键(key)-值(value)对集合,Map中的每个元素都是一个键值对,其中key只能有一个为null且key不能重复(唯一),而v ...
- 使用Java Stream API将List按自定义分组规则转换成Map的一个例子
本文完整测试代码见文末. 测试数据是List里的4个员工对象实例: 根据员工所在的城市进行分组: 结果分成了三组: 第一组的员工在上海: 第二组的员工在成都: 统计每组员工个数: 把员工进行分组,得分 ...
最新文章
- [2008.06.10 23:20:00] 心智成熟的旅程
- 重启openssl服务linux,Nginx的启动、停止与重启---linux
- vbs劫持快捷键并执行程序
- 遨游金山网盾?蹦出来有啥用?
- mysql_rollback_MySQL的rollback--事务回滚
- 处女座的签到题 (暴力+局部排序)
- bzoj 1028: [JSOI2007]麻将
- 广西二级c语言试题,广西区计算机等级考二级C语言笔试试题及答案.doc
- 使用MFC开发ActiveX控件
- 73. 简化 CSS 选择符
- extern dllInport用法
- c语言二级编程题库,计算机二级C语言编程题库(100题)
- sqlplus命令支持上、下翻功能
- html制作公众号,自制微信公众号一键排版工具
- 一起学爬虫(Python) — 02
- C++核心准则​Pro.bounds:边界安全群组
- 计算机组成原理(笔记)
- LATEX--页边距设置
- 使用RSD对高分1号卫星数据进行批量大气校正
- MOS驱动电机正反转
热门文章
- matlab自定义函数的使用方法,Matlab自定义函数的几种方法
- [转]IIS网站真正301重定向的方法(任意页面,含问号参数)
- 前端面试题:Token一般是存放在哪里 Token放在cookie和放在localStorage、sessionStorage中有什么不同
- 安装mingw+Theano+keras(多警告、错误解决办法)
- 影石创新在科创板递交招股书注册稿,共有492件专利申请信息
- 41个搜索引擎免费登陆入口大全
- 逻辑与、逻辑或||的注意项
- 电脑网络里面无法显示本计算机,电脑的本地连接不见了怎么办 电脑的本地连接不见了解决方法...
- 深圳绿道最全资料合集_我是亲民_新浪博客
- 新书《Linux就是这个范儿》预售