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

article/2025/10/28 8:28:52

直接上代码 实体类

@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

在这里插入图片描述

这辈子坚持与不坚持都不可怕,怕的是独自走在坚持的道路上!!! 欢迎加入技术群聊。

在这里插入图片描述


http://chatgpt.dhexx.cn/article/9iQjcJJt.shtml

相关文章

Map集合的entrySet()方法

之前学习集合的时候要通过迭代器来迭代的时候最难得就是map集合得迭代&#xff0c;一直也不太明白&#xff0c;今天总算搞懂了 首先我们看什么容器才能迭代 根据API我们得知是对所有collection迭代的集合&#xff0c;那么已知的collection容器有哪些 我把常用的标出了&#xf…

keySet()和entrySet()

一、描述 keySet()和entrySet()&#xff0c;是Map集合中的两种取值方法。 与get(Object key)相比&#xff0c;get(Object key)只能返回到指定键所映射的值&#xff0c;不能一次全部取出。而keySet()和entrySet()可以。 Map集合中没有迭代器&#xff0c;Map集合取出键值的原理…

Java高级之HashMap中的entrySet()方法

基本使用 entrySet()方法得到HashMap中各个键值对映射关系的集合。 然后Map.Entry中包含了getKey()和getValue()方法获取键和值。 示例&#xff1a; public class Demo {public static void main(String[] args) {Map<String, String> map new HashMap<>();ma…

KeySet和EntrySet区别

场景&#xff1a; keySet()和entrySet()&#xff0c;是Map集合中的两种取值方法。 与get(Object key)相比&#xff0c;get(Object key)只能返回到指定键所映射的值&#xff0c;不能一次全部取出。而keySet()和entrySet()可以。 Map集合中没有迭代器&#xff0c;Map集合取出键…

Map中entrySet()方法使用

public Set<Map.Entry<K,V>> entrySet(): 获取到Map集合中所有的键值对对象的集合(Set集合)。 就是返回一个集合&#xff0c;集合里存放的是对象&#xff0c;创建对象的类有两个属性&#xff0c;分别是 键和值 也即键值对。 其中Entry是属于Map的静态内部类&#x…

glPushMatrix 和glPopMatrix图解 ----求别笑

猜想&#xff1a; openGL在绘制场景时的一般用法是&#xff1a; 首先在函数的开始处用glLoadIdentity()设置当前的矩阵为单位矩阵。 然后在函数中用glPushMatrix()和glPopMatrix()函数进行操作&#xff1a; 根据实践判断&#xff1a; 即这两者是分开的&#xff0c;并不是当前…

OpenGL的glPushMatrix和glPopMatrix矩阵栈顶操作函数详解

OpenGL中图形绘制后&#xff0c;往往需要一系列的变换来达到用户的目的&#xff0c;而这种变换实现的原理是又通过矩阵进行操作的。opengl中的变换一般包括视图变换、模型变换、投影变换等&#xff0c;在每次变换后&#xff0c;opengl将会呈现一种新的状态&#xff08;这也就是…

为什么调用glPushMatrix()和glPopMatrix()

2019独角兽企业重金招聘Python工程师标准>>> 今天忽然感悟到为什么在进行变换之前要用glPushMatrix();这个函数&#xff0c;而在变换完毕后有用glPopMatrix()这两个函数了,赶紧记下来&#xff1a; 我们在变换坐标的时候&#xff0c;使用的是glTranslatef(),glRotaef…

opengl入门记录--glPushMatrix和glPopMatrix原理

glPushMatrix、glPopMatrix操作事实上就相当于栈里的入栈和出栈。 很多人不明确的可能是入的是什么&#xff0c;出的又是什么。 比如你当前的坐标系原点在你电脑屏幕的左上方。如今你调用glPushMatrix&#xff0c;然后再调用一堆平移、旋转代码等等&#xff0c;然后再绘图。那…

OpenGL编程指南9:裁剪平面+glPushMatrix和glPopMatrix矩阵栈顶操作

1.任意裁剪平面 Opengl中&#xff0c;除了视景体的立方体裁剪平面之外&#xff0c;另外还可以额外指定多达6个裁剪平面&#xff0c;对视景体做进一步限制。每一个平面都由平面公式定义&#xff1a;AxByCzD 0.裁剪平面的指定通过函数&#xff1a;glClipPlane(GLenum plane,cons…

使用glPushMatrix和glPopMatrix的原因

转自 百度百科 glPushMatrix 函数将当前矩阵堆栈推送&#xff0c;通过一个&#xff0c;复制当前矩阵。 这就是后 glPushMatrix 的调用堆栈的顶部矩阵是它下面的相同的。 1. 原理讲解 终于明白为什么使用glPushMatrix()和glPopMatrix()的原因了。将本次需要执行的缩放、平移等操…

【已解决】DQN报错:NameError: name ‘glPushMatrix‘ is not defined

1、问题 pycharm在运行DQN平衡杆代码时报错&#xff1a;NameError: name ‘glPushMatrix’ is not defined。 画面只出现一个白色背景。 2、分析 pyglet版本过高&#xff0c;降低版本即可。 pip install pyglet1.5.273、测试 没有报错&#xff0c;运行成功。 参考链接…

opengl glPushMatrix()

OpenGL有三个矩阵堆栈&#xff0c;分别是GL_MODELVIEW&#xff08;模型视图矩阵堆栈&#xff09;、GL_PROJECTION&#xff08;投影矩阵堆栈&#xff09;、GL_TEXTURE&#xff08;纹理矩阵堆栈&#xff09;&#xff0c;用法和普通堆栈一样&#xff1b; 这里我们只讲模型视图矩阵…

解决:nameerror: name ‘glpushmatrix‘ is not defined

在尝试gym的render()时&#xff0c;出现错误&#xff1a; nameerror: name glpushmatrix is not defined最后解决的办法&#xff1a;更换pyglet包的版本 出现错误时的pyglet版本&#xff1a; 然后将版本更换为&#xff1a; 就可以使用env.render()啦&#xff01;

NameError: name ‘glPushMatrix‘ is not defined

完整报错如下图所示&#xff1a; 问题原因&#xff1a;pyglet版本导致 我本地安装的pyglet版本是2.0.7改成&#xff0c;问题解决 pip install pyglet1.5.0

glPushMatrix()和glPopmatirx()

OpenGL有三个矩阵堆栈&#xff0c;分别是GL_MODELVIEW&#xff08;模型视图矩阵堆栈&#xff09;、GL_PROJECTION&#xff08;投影矩阵堆栈&#xff09;、GL_TEXTURE&#xff08;纹理矩阵堆栈&#xff09;&#xff0c;用法和普通堆栈一样&#xff1b; 这里我们只讲模型视图矩阵…

OpenGL:glPushMatrix();和glPopMatrix();的作用及其原理分析

今天做到一道题&#xff0c;大致就是问glPushMatrix();和glPopMatrix();存在会对图形绘制造成什么影响&#xff0c;为了能够清晰的反应到底会存在什么影响&#xff0c;我特地写了两行代码&#xff1a; 代码①&#xff1a; void draw1() {//glClear(GL_COLOR_BUFFER_BIT); //注…

OpenGL的glPushMatrix和glPopMatrix矩阵栈顶操作函数

在之前的博客中&#xff0c;我就说过后面会详细讲解这两个函数。今天让我们来认识下它们&#xff08;glPushMatrix和glPopMatrix函数&#xff09;。 OpenGL中图形绘制后&#xff0c;往往需要一系列的变换来达到用户的目的&#xff0c;而这种变换实现的原理是又通过矩阵进行操作…

SurfaceView、GLSurfaceView、SurfaceTexture、TextureView、SurfaceHolder、Surface

SurfaceView、GLSurfaceViewe\SurfaceTexture、TextureView、SurfaceHolder、Surface 一、简介 SurfaceTexture: SurfaceTexture是从Android3.0&#xff08;API 11&#xff09;加入的一个新类。这个类跟SurfaceView很像&#xff0c;可以从video decode里面获取图像流&#xff…

android之通过SurfaceView以及SurfaceHolder进行视频播放

使用AudioView进行视频播放的时候&#xff0c;是不是很不爽&#xff0c;千篇一律的模式&#xff0c;恶心吧。这里&#xff0c;我们可以通过一些方式对MediaPlayer进行包装。而所用到的正是SurfaceView以及SurfaceHolder。 最终效果图&#xff1a; 我们提供了四个按钮&#xff…