Map.Entry与entrySet与entry,getKey()与entry.getValue()的用法

2024-03-11 03:08

本文主要是介绍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()的用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/796409

相关文章

bytes.split的用法和注意事项

当然,我很乐意详细介绍 bytes.Split 的用法和注意事项。这个函数是 Go 标准库中 bytes 包的一个重要组成部分,用于分割字节切片。 基本用法 bytes.Split 的函数签名如下: func Split(s, sep []byte) [][]byte s 是要分割的字节切片sep 是用作分隔符的字节切片返回值是一个二维字节切片,包含分割后的结果 基本使用示例: pa

Collection List Set Map的区别和联系

Collection List Set Map的区别和联系 这些都代表了Java中的集合,这里主要从其元素是否有序,是否可重复来进行区别记忆,以便恰当地使用,当然还存在同步方面的差异,见上一篇相关文章。 有序否 允许元素重复否 Collection 否 是 List 是 是 Set AbstractSet 否

UVM:callback机制的意义和用法

1. 作用         Callback机制在UVM验证平台,最大用处就是为了提高验证平台的可重用性。在不创建复杂的OOP层次结构前提下,针对组件中的某些行为,在其之前后之后,内置一些函数,增加或者修改UVM组件的操作,增加新的功能,从而实现一个环境多个用例。此外还可以通过Callback机制构建异常的测试用例。 2. 使用步骤         (1)在UVM组件中内嵌callback函

这些ES6用法你都会吗?

一 关于取值 取值在程序中非常常见,比如从对象obj中取值 const obj = {a:1b:2c:3d:4} 吐槽: const a = obj.a;const b = obj.b;const c = obj.c;//或者const f = obj.a + obj.b;const g = obj.c + obj.d; 改进:用ES6解构赋值

2021-8-14 react笔记-2 创建组件 基本用法

1、目录解析 public中的index.html为入口文件 src目录中文件很乱,先整理文件夹。 新建components 放组件 新建assets放资源   ->/images      ->/css 把乱的文件放进去  修改App.js 根组件和index.js入口文件中的引入路径 2、新建组件 在components文件夹中新建[Name].js文件 //组件名首字母大写

Cmake之3.0版本重要特性及用法实例(十三)

简介: CSDN博客专家、《Android系统多媒体进阶实战》一书作者 新书发布:《Android系统多媒体进阶实战》🚀 优质专栏: Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏: 多媒体系统工程师系列【原创干货持续更新中……】🚀 优质视频课程:AAOS车载系统+AOSP14系统攻城狮入门视频实战课 🚀 人生格言: 人生从来没有捷径,只有行动才是治疗恐惧

关于断言的部分用法

1、带变量的断言  systemVerilog assertion 中variable delay的使用,##[variable],带变量的延时(可变延时)_assertion中的延时-CSDN博客 2、until 的使用 systemVerilog assertion 中until的使用_verilog until-CSDN博客 3、throughout的使用   常用于断言和假设中的

ExpandableListView的基本用法

QQ上的好友列表在Android怎么实现,有一个最简单的方法,那就是ExpandableListView,下面简单介绍一下ExpandableListview的用法。 先看看效果图,没有找到大小合适的图片,所以凑合着看吧。     一、准备工作(界面,和需要的数据)             <? xml   version = "1.0"   encoding =

Hbase 查询相关用法

Hbase 查询相关用法 public static void main(String[] args) throws IOException {//Scan类常用方法说明//指定需要的family或column ,如果没有调用任何addFamily或Column,会返回所有的columns; // scan.addFamily(); // scan.addColumn();// scan.se

BeanUtils.copyProperties()在不同包下,用法不同!!! 切记!!!

用法一: 在import org.springframework.beans.BeanUtils;包下: <span style="white-space:pre"> </span>//赋值vo对象的值到po中 <span style="white-space:pre"> </span>/** <span style="white-space:pre"> </span>* <spa