Java ArrayList在遍历时删除元素
文章目录
- 1. Arrays.asList()获取到的ArrayList只能遍历,不能增加或删除元素
- 2. java.util.ArrayList.SubList有实现add()、remove()方法
- 3. 遍历集合时对元素重新赋值、对元素中的属性赋值、删除元素、新增元素
- 3.1 普通for循环
- 3.2 增强for循环
- 3.3 forEach循环
- 3.4 stream forEach循环
- 3.5 迭代器
- 4. 对大集合进行分组,遍历分组后的大集合,各个子集合使用完成后立即将元素删除
我们常说的ArrayList是指java.util.ArrayList
1. Arrays.asList()获取到的ArrayList只能遍历,不能增加或删除元素
Arrays.asList()获取到的ArrayList不是java.util包下的,而是java.util.Arrays.ArrayList;
它是Arrays类自己定义的一个静态内部类,这个内部类没有实现add()、remove()方法,而是直接使用它的父类AbstractList的相应方法。而AbstractList中的add()和remove()是直接抛出java.lang.UnsupportedOperationException异常
public static void main(String[] args) {List<String> list = Arrays.asList("xin", "liu", "shijian");// 遍历 oklist.stream().forEach(System.out::println);for (int i = 0; i < list.size(); i++) {// 报异常:UnsupportedOperationExceptionlist.add("haha");// 报异常:UnsupportedOperationExceptionlist.remove(i);}
}
2. java.util.ArrayList.SubList有实现add()、remove()方法
java.util.ArrayList.SubList 是ArrayList的内部类,可以add 和 remove
不建议对得到的子集合进行增、删操作
public static void main(String[] args) {List<PersonDTO> list = getDataList();List<PersonDTO> subList = list.subList(0, 2);int size = subList.size();for (int i = 0; i < size; i++) {PersonDTO personDTO = subList.get(i);if (i == 0) {
// subList.remove(personDTO);subList.add(personDTO);break;}}System.out.println(list);}
3. 遍历集合时对元素重新赋值、对元素中的属性赋值、删除元素、新增元素
遍历方式:普通for循环、增强for循环、forEach、stream forEach、迭代器
- 对元素重新赋值:各种遍历方式都做不到
- 对元素中的属性赋值:各种遍历方式都能做到
- 对集合新增元素:普通for循环可以做到,其他遍历方式都做不到
- 对集合删除元素:普通for循环和迭代器可以做到,其他方式都做不到
建议:遍历集合时删除元素用迭代器、新增元素可以新建一个集合
准备实验数据
private static List<PersonDTO> getDataList() {List<PersonDTO> list = new ArrayList<>();PersonDTO p1 = new PersonDTO();p1.setPersonName("xiaohua1");PersonDTO p2 = new PersonDTO();p2.setPersonName("xiaohua2");PersonDTO p3 = new PersonDTO();p3.setPersonName("xiaohua3");PersonDTO p4 = new PersonDTO();p4.setPersonName("xiaohua4");PersonDTO p5 = new PersonDTO();p5.setPersonName("xiaohua5");PersonDTO p6 = new PersonDTO();p6.setPersonName("xiaohua6");list.add(p1);list.add(p2);list.add(p3);list.add(p4);list.add(p5);list.add(p6);return list;}
3.1 普通for循环
普通for循环,遍历元素时重新赋值失败
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (int i = 0; i < list.size(); i++) {// 原因是这里personDTO是另一个栈变量,并不会对集合中的栈内容(对象在内存中的地址)进行改变PersonDTO personDTO = list.get(i);personDTO = null;}System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=null), PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua3, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua5, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null)]
普通for循环,遍历元素时,对元素中的属性成功赋值
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (int i = 0; i < list.size(); i++) {// 成功是因为它们虽然是不同的变量,但栈内容相同,都是同一个对象的内存地址,这里会更改到堆中对象的内容PersonDTO personDTO = list.get(i);personDTO.setAge(5);}System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=5), PersonDTO(bookEntityList=null, personName=xiaohua2, age=5), PersonDTO(bookEntityList=null, personName=xiaohua3, age=5), PersonDTO(bookEntityList=null, personName=xiaohua4, age=5), PersonDTO(bookEntityList=null, personName=xiaohua5, age=5), PersonDTO(bookEntityList=null, personName=xiaohua6, age=5)]
普通for循环遍历时删除元素,ok
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (int i = 0; i < list.size(); i++) {PersonDTO personDTO = list.get(i);list.remove(personDTO);}System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null)]
普通for循环遍历时新增元素,size若不固定,报异常OutOfMemoryError
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (int i = 0; i < list.size(); i++) {PersonDTO personDTO = list.get(i);list.add(personDTO);System.out.println("list.size(): " + list.size());}System.out.println(list);}
打印结果:
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3210)
at java.util.Arrays.copyOf(Arrays.java:3181)
at java.util.ArrayList.grow(ArrayList.java:267)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:241)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:233)
at java.util.ArrayList.add(ArrayList.java:464)
后来又执行一次,到这个数据量还未结束
list.size(): 43014827
list.size(): 43014828
list.size(): 43014829
Process finished with exit code 130
Java VisualVM监视图如下:
换种写法,固定size值,就运行ok了,普通for循环遍历时就可以新增元素了
public static void main(String[] args) {List<PersonDTO> list = getDataList();int size = list.size();for (int i = 0; i < size; i++) {PersonDTO personDTO = list.get(i);list.add(personDTO);System.out.println("list.size(): " + list.size());}System.out.println(list);}
打印结果:
list.size(): 7
list.size(): 8
list.size(): 9
list.size(): 10
list.size(): 11
list.size(): 12
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=null), PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua3, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua5, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null), PersonDTO(bookEntityList=null, personName=xiaohua1, age=null), PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua3, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua5, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null)]
3.2 增强for循环
增强for循环,遍历元素时重新赋值失败
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (PersonDTO dto : list) {// 增强for循环内部实现是迭代器,我认为是调用了新方法,进行了值传递,dto是另一个变量了dto = null;}System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=null), PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua3, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua5, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null)]
增强for循环,遍历元素时,对元素中的属性成功赋值
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (PersonDTO dto : list) {dto.setAge(7);}System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=7), PersonDTO(bookEntityList=null, personName=xiaohua2, age=7), PersonDTO(bookEntityList=null, personName=xiaohua3, age=7), PersonDTO(bookEntityList=null, personName=xiaohua4, age=7), PersonDTO(bookEntityList=null, personName=xiaohua5, age=7), PersonDTO(bookEntityList=null, personName=xiaohua6, age=7)]
增强for循环遍历时删除元素,报异常ConcurrentModificationException
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (PersonDTO dto : list) {list.remove(dto);}System.out.println(list);}
打印结果:
Exception in thread “main” java.util.ConcurrentModificationException
at java.util.ArrayList I t r . c h e c k F o r C o m o d i f i c a t i o n ( A r r a y L i s t . j a v a : 911 ) a t j a v a . u t i l . A r r a y L i s t Itr.checkForComodification(ArrayList.java:911) at java.util.ArrayList Itr.checkForComodification(ArrayList.java:911)atjava.util.ArrayListItr.next(ArrayList.java:861)
增强for循环遍历时新增元素,报异常ConcurrentModificationException
public static void main(String[] args) {List<PersonDTO> list = getDataList();for (PersonDTO dto : list) {list.add(dto);}System.out.println(list);}
打印结果:
Exception in thread “main” java.util.ConcurrentModificationException
at java.util.ArrayList I t r . c h e c k F o r C o m o d i f i c a t i o n ( A r r a y L i s t . j a v a : 911 ) a t j a v a . u t i l . A r r a y L i s t Itr.checkForComodification(ArrayList.java:911) at java.util.ArrayList Itr.checkForComodification(ArrayList.java:911)atjava.util.ArrayListItr.next(ArrayList.java:861)
3.3 forEach循环
forEach循环,遍历元素时重新赋值失败
public static void main(String[] args) {List<PersonDTO> list = getDataList();// forEach循环内部实现是匿名内部类,调用了函数式接口的新方法,进行了值传递,dto是另一个变量了list.forEach(dto -> dto = null);System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=null), PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua3, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua5, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null)]
forEach循环,遍历元素时,对元素中的属性成功赋值
public static void main(String[] args) {List<PersonDTO> list = getDataList();list.forEach(dto -> dto.setAge(6));System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=6), PersonDTO(bookEntityList=null, personName=xiaohua2, age=6), PersonDTO(bookEntityList=null, personName=xiaohua3, age=6), PersonDTO(bookEntityList=null, personName=xiaohua4, age=6), PersonDTO(bookEntityList=null, personName=xiaohua5, age=6), PersonDTO(bookEntityList=null, personName=xiaohua6, age=6)]
forEach循环遍历时删除元素,报异常ConcurrentModificationException
public static void main(String[] args) {List<PersonDTO> list = getDataList();list.forEach(dto -> list.remove(dto));System.out.println(list);}
打印结果:
Exception in thread “main” java.util.ConcurrentModificationException
at java.util.ArrayList.forEach(ArrayList.java:1262)
forEach循环遍历时新增元素,报异常ConcurrentModificationException
public static void main(String[] args) {List<PersonDTO> list = getDataList();list.forEach(dto -> list.add(new PersonDTO()));System.out.println(list);}
打印结果:
Exception in thread “main” java.util.ConcurrentModificationException
at java.util.ArrayList.forEach(ArrayList.java:1262)
3.4 stream forEach循环
stream forEach循环,遍历元素时重新赋值失败
public static void main(String[] args) {List<PersonDTO> list = getDataList();// stream forEach循环内部实现是匿名内部类,调用了函数式接口的新方法,进行了值传递,dto是另一个变量了list.stream().forEach(dto -> dto = null);System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=null), PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua3, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua5, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null)]
stream forEach循环,遍历元素时,对元素中的属性成功赋值
public static void main(String[] args) {List<PersonDTO> list = getDataList();list.stream().forEach(dto -> dto.setAge(8));System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=8), PersonDTO(bookEntityList=null, personName=xiaohua2, age=8), PersonDTO(bookEntityList=null, personName=xiaohua3, age=8), PersonDTO(bookEntityList=null, personName=xiaohua4, age=8), PersonDTO(bookEntityList=null, personName=xiaohua5, age=8), PersonDTO(bookEntityList=null, personName=xiaohua6, age=8)]
stream forEach循环遍历时删除元素,报异常ConcurrentModificationException
public static void main(String[] args) {List<PersonDTO> list = getDataList();list.stream().forEach(dto -> list.remove(dto));System.out.println(list);}
打印结果:
Exception in thread “main” java.util.ConcurrentModificationException
at java.util.ArrayList.forEach(ArrayList.java:1262)
stream forEach循环遍历时新增元素,报异常ConcurrentModificationException
public static void main(String[] args) {List<PersonDTO> list = getDataList();list.stream().forEach(dto -> list.add(new PersonDTO()));System.out.println(list);}
打印结果:
Exception in thread “main” java.util.ConcurrentModificationException
at java.util.ArrayList A r r a y L i s t S p l i t e r a t o r . f o r E a c h R e m a i n i n g ( A r r a y L i s t . j a v a : 1390 ) a t j a v a . u t i l . s t r e a m . R e f e r e n c e P i p e l i n e ArrayListSpliterator.forEachRemaining(ArrayList.java:1390) at java.util.stream.ReferencePipeline ArrayListSpliterator.forEachRemaining(ArrayList.java:1390)atjava.util.stream.ReferencePipelineHead.forEach(ReferencePipeline.java:580)
3.5 迭代器
迭代器循环,遍历元素时重新赋值失败
public static void main(String[] args) {List<PersonDTO> list = getDataList();Iterator<PersonDTO> iterator = list.iterator();while (iterator.hasNext()) {// 原因是这里dto是另一个栈变量,并不会对集合中的栈内容(对象在内存中的地址)进行改变PersonDTO dto = iterator.next();dto = null;}System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=null), PersonDTO(bookEntityList=null, personName=xiaohua2, age=null), PersonDTO(bookEntityList=null, personName=xiaohua3, age=null), PersonDTO(bookEntityList=null, personName=xiaohua4, age=null), PersonDTO(bookEntityList=null, personName=xiaohua5, age=null), PersonDTO(bookEntityList=null, personName=xiaohua6, age=null)]
迭代器循环,遍历元素时,对元素中的属性成功赋值
public static void main(String[] args) {List<PersonDTO> list = getDataList();Iterator<PersonDTO> iterator = list.iterator();while (iterator.hasNext()) {PersonDTO dto = iterator.next();dto.setAge(9);}System.out.println(list);}
打印结果:
[PersonDTO(bookEntityList=null, personName=xiaohua1, age=9), PersonDTO(bookEntityList=null, personName=xiaohua2, age=9), PersonDTO(bookEntityList=null, personName=xiaohua3, age=9), PersonDTO(bookEntityList=null, personName=xiaohua4, age=9), PersonDTO(bookEntityList=null, personName=xiaohua5, age=9), PersonDTO(bookEntityList=null, personName=xiaohua6, age=9)]
迭代器遍历时删除元素,可以成功
public static void main(String[] args) {List<PersonDTO> list = getDataList();Iterator<PersonDTO> iterator = list.iterator();while (iterator.hasNext()) {PersonDTO dto = iterator.next();iterator.remove();}System.out.println(list);}
打印结果:
[]
迭代器遍历时新增元素,报异常:ConcurrentModificationException
public static void main(String[] args) {List<PersonDTO> list = getDataList();Iterator<PersonDTO> iterator = list.iterator();while (iterator.hasNext()) {PersonDTO dto = iterator.next();list.add(new PersonDTO());}System.out.println(list);}
打印结果:
Exception in thread “main” java.util.ConcurrentModificationException
at java.util.ArrayList I t r . c h e c k F o r C o m o d i f i c a t i o n ( A r r a y L i s t . j a v a : 911 ) a t j a v a . u t i l . A r r a y L i s t Itr.checkForComodification(ArrayList.java:911) at java.util.ArrayList Itr.checkForComodification(ArrayList.java:911)atjava.util.ArrayListItr.next(ArrayList.java:861)
4. 对大集合进行分组,遍历分组后的大集合,各个子集合使用完成后立即将元素删除
场景:集合中对象比较多,可能造成OOM,集合中的一部分元素使用完成后立即删除
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;public class ArrayListDemo {private static final int SUBLIST_SIZE = 2;public static void main(String[] args) {// 不适合list中有元素减少的场景// 1.得到总list,这个时候的list接下来还可能会继续扩展List<PersonDTO> list = getDataList();System.out.println("刚开始, list.size = " + list.size());// 2.业务逻辑代码:list还可能会扩展// 3.处理完子集合,就删除它的元素deleteSubList(list);System.out.println("处理一波后, list.size = " + list.size());// 4.list不再扩展,删除剩下元素,也是一个一个子集合的删除元素deleteSubList(list, false);System.out.println("最后处理后, list.size = " + list.size());}private static void deleteSubList(List<PersonDTO> list) {// isNotEnd 代表list集合可能还会增加元素deleteSubList(list, true);}private static void deleteSubList(List<PersonDTO> list, boolean isNotEnd) {if (Objects.isNull(isNotEnd)) {isNotEnd = false;}if (CollectionUtils.isNotEmpty(list) && ((list.size() > SUBLIST_SIZE) || !isNotEnd)) {int size = list.size() / SUBLIST_SIZE;if ((list.size() % SUBLIST_SIZE) > 0) {size++;}for (int i = 0; i < size; i++) {if (CollectionUtils.isNotEmpty(list)) {List<PersonDTO> subList = Lists.partition(list, SUBLIST_SIZE).get(0);// 不再继续处理业务逻辑: list中的数据量小于SUBLIST_SIZE && list中还可能增加元素if ((list.size() < SUBLIST_SIZE) && isNotEnd) {break;}// 使用subList处理业务逻辑// 删出list中的subListIterator<PersonDTO> iterator = list.iterator();int j = 0;while (iterator.hasNext()) {iterator.next();j++;if (j <= SUBLIST_SIZE) {iterator.remove();}if (j > SUBLIST_SIZE) {break;}}System.out.println("删除subList后, list.size = " + list.size());}}}}private static List<PersonDTO> getDataList() {List<PersonDTO> list = new ArrayList<>();PersonDTO p1 = new PersonDTO();p1.setPersonName("xiaohua1");PersonDTO p2 = new PersonDTO();p2.setPersonName("xiaohua2");PersonDTO p3 = new PersonDTO();p3.setPersonName("xiaohua3");PersonDTO p4 = new PersonDTO();p4.setPersonName("xiaohua4");PersonDTO p5 = new PersonDTO();p5.setPersonName("xiaohua5");PersonDTO p6 = new PersonDTO();p6.setPersonName("xiaohua6");PersonDTO p7 = new PersonDTO();p7.setPersonName("xiaohua7");list.add(p1);list.add(p2);list.add(p3);list.add(p4);list.add(p5);list.add(p6);list.add(p7);return list;}
}
打印结果:
刚开始, list.size = 7
删除subList后, list.size = 5
删除subList后, list.size = 3
删除subList后, list.size = 1
处理一波后, list.size = 1
删除subList后, list.size = 0
最后处理后, list.size = 0
相关文章:

Java ArrayList在遍历时删除元素
文章目录 1. Arrays.asList()获取到的ArrayList只能遍历,不能增加或删除元素2. java.util.ArrayList.SubList有实现add()、remove()方法3. 遍历集合时对元素重新赋值、对元素中的属性赋值、删除元素、新增元素3.1 普通for循环3.2 增强for循环3.3 forEach循环3.4 str…...

多模态大模型的前世今生
1 引言 前段时间 ChatGPT 进行了一轮重大更新:多模态上线,能说话,会看图!微软发了一篇长达 166 页的 GPT-4V 测评论文,一时间又带起了一阵多模态的热议,随后像是 LLaVA-1.5、CogVLM、MiniGPT-5 等研究工作…...

Android studio 花式按键
一、activity_main.xml代码: <?xml version"1.0" encoding"utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.a…...

使用spring boot实现异常的统一返回
在这个前后端分离的时代,一个 统一的数据格式非常重要。本次我们实现用spring boot实现一下返回给前端数据的统一格式,不再出现服务器500的错误。 新建一个spring boot项目,并导入knife4j的依赖。 写一个controller控制器,用来是…...

2023-12-11 LeetCode每日一题(最小体力消耗路径)
2023-12-11每日一题 一、题目编号 1631. 最小体力消耗路径二、题目链接 点击跳转到题目位置 三、题目描述 你准备参加一场远足活动。给你一个二维 rows x columns 的地图 heights ,其中 heights[row][col] 表示格子 (row, col) 的高度。一开始你在最左上角的格…...
PID为1的僵尸进程的产生及清理
父进程PID为1的僵尸进程通常是由init系统(在Linux系统中通常是systemd)产生的。这种情况通常发生在以下几种情况: 子进程结束,但其父进程没有正确地调用wait()或waitpid()系统调用来获取子进程的退出状态。在这种情况下࿰…...

043、循环神经网络
之——RNN基础 杂谈 第一个对于序列模型的网络,RNN。 正文 1.潜变量自回归模型 潜变量总结过去的信息,再和当前信息一起结合出新的信息。 2.RNN 循环神经网络将观察作为x,与前层隐变量结合得到输出 其中Whh蕴含了整个模型的时序信息…...
node使用nodemonjs自动启动项目
安装 npm install -g nodemon使用方法 我这里用的是electron项目为例package.json配置 {"name": "my-electron-app","version": "1.0.0","description": "Hello World!","main": "main.js"…...

Ts自封装WebSocket心跳重连
WebSocket是一种在单个TCP连接上进行全双工通信的协议,允许客户端和服务器之间进行双向实时通信。 所谓心跳机制,就是在长时间不使用WebSocket连接的情况下,通过服务器与客户端之间按照一定时间间隔进行少量数据的通信来达到确认连接稳定的手…...

【unity学习笔记】捏人+眨眼效果+口型效果
一、vriod捏人 1.在vroidstudio软件中捏人 2.导出模型(.vrm) 二、vrid导入unity的插件 1.在Git上搜索、打开univrm。 2.找到release页面找到合适的插件版本。(VRM-0.116.0_0f6c) 3.将univrm导入到工程中(assets)。 三…...
动态规划 | 最长公共子序列问题
文章目录 最长公共子序列题目描述问题分析程序代码复杂度分析 最短编辑距离题目描述问题分析程序代码复杂度分析 编辑距离题目描述输入格式输出格式 问题分析程序代码 最长公共子序列 题目描述 原题链接 给定两个字符串 text1 和 text2,返回这两个字符串的最长 公共…...

RuntimeError: The NVIDIA driver on your system is too old.
【报错】使用 AutoDL 复现实验时遇到 RuntimeError: The NVIDIA driver on your system is too old (found version 11070). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternativ…...

Java开发过程中的幂等性问题
幂等性问题: 1. 有时我们在填写某些 form表单 时,保存按钮不小心快速点了两次,表中竟然产生了两条重复的数据,只是id不一样。 2. 我们在项目中为了解决 接口超时 问题,通常会引入了 重试机制 。第一次请求接口超时了…...

基于Docker的软件环境部署脚本,持续更新~
使用时CtrlF搜索你想要的环境,如果没有你想要的环境,可以评论留言,会尽力补充。 本文提供的部署脚本默认参数仅适合开发测试,请根据实际情况调节参数。 数据库 MySQL version: 3.9 services:mysql:image: mysql:8.0.35container…...

C#上位机与欧姆龙PLC的通信08----开发自己的通讯库读写数据
1、介绍 前面已经完成了7项工作: C#上位机与欧姆龙PLC的通信01----项目背景-CSDN博客 C#上位机与欧姆龙PLC的通信02----搭建仿真环境-CSDN博客 C#上位机与欧姆龙PLC的通信03----创建项目工程-CSDN博客 C#上位机与欧姆龙PLC的通信04---- 欧姆龙plc的存储区 C#上…...

【Redis技术专区】「原理分析」探讨Redis6.0为何需要启用多线程
探讨Redis 6.0为何需要启用多线程 背景介绍开启多线程多线程的CPU核心配置IO多线程模式单线程处理方式多线程处理方式 为什么要开启多线程?充分利用多核CPU提高网络I/O效率响应现代应用需求 多线程实现启用多线程 最后总结 背景介绍 在Redis 6.0版本中,…...

simulink代码生成(六)——多级中断的配置
假如系统中存在多个中断,需要合理的配置中断的优先级与中断向量表;在代码生成中,要与中断向量表对应;中断相关的知识参照博客: DSP28335学习——中断向量表的初始化_中断向量表什么时候初始化-CSDN博客 F28335中断系…...

【Minikube Prometheus】基于Prometheus Grafana监控由Minikube创建的K8S集群
文章目录 1. 系统信息参数说明2. Docker安装3. minikube安装4. kubectl安装5. Helm安装6. 启动Kubernetes集群v1.28.37. 使用helm安装Prometheus8. 使用helm安装Grafana9. Grafana的Dashboard设定10. 设定Prometheus数据源11. 导入Kubernetes Dashboard12. 实验过程中的常见问题…...

无需翻墙|Stable Diffusion WebUI 安装|AI绘画
前言 最近终于有机会从围墙里往外看,了解到外面的世界已经有了天翻地覆的变化,感叹万千,笔者在本地mac,windows,linux,docker部署了不下20遍后,整理出来的linux极简避坑安装方案,供…...

在FC中手工创建虚拟机模板
1、Linux去除个性化信息 (1)编辑网卡配置文件,只保留以下内容(以RHEL 7为例) (2)清除主机密钥信息(开机会自动生成) (3)清除Machine IDÿ…...

基于距离变化能量开销动态调整的WSN低功耗拓扑控制开销算法matlab仿真
目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.算法仿真参数 5.算法理论概述 6.参考文献 7.完整程序 1.程序功能描述 通过动态调整节点通信的能量开销,平衡网络负载,延长WSN生命周期。具体通过建立基于距离的能量消耗模型&am…...

(二)原型模式
原型的功能是将一个已经存在的对象作为源目标,其余对象都是通过这个源目标创建。发挥复制的作用就是原型模式的核心思想。 一、源型模式的定义 原型模式是指第二次创建对象可以通过复制已经存在的原型对象来实现,忽略对象创建过程中的其它细节。 📌 核心特点: 避免重复初…...
oracle与MySQL数据库之间数据同步的技术要点
Oracle与MySQL数据库之间的数据同步是一个涉及多个技术要点的复杂任务。由于Oracle和MySQL的架构差异,它们的数据同步要求既要保持数据的准确性和一致性,又要处理好性能问题。以下是一些主要的技术要点: 数据结构差异 数据类型差异ÿ…...

Map相关知识
数据结构 二叉树 二叉树,顾名思义,每个节点最多有两个“叉”,也就是两个子节点,分别是左子 节点和右子节点。不过,二叉树并不要求每个节点都有两个子节点,有的节点只 有左子节点,有的节点只有…...
【碎碎念】宝可梦 Mesh GO : 基于MESH网络的口袋妖怪 宝可梦GO游戏自组网系统
目录 游戏说明《宝可梦 Mesh GO》 —— 局域宝可梦探索Pokmon GO 类游戏核心理念应用场景Mesh 特性 宝可梦玩法融合设计游戏构想要素1. 地图探索(基于物理空间 广播范围)2. 野生宝可梦生成与广播3. 对战系统4. 道具与通信5. 延伸玩法 安全性设计 技术选…...

Mysql中select查询语句的执行过程
目录 1、介绍 1.1、组件介绍 1.2、Sql执行顺序 2、执行流程 2.1. 连接与认证 2.2. 查询缓存 2.3. 语法解析(Parser) 2.4、执行sql 1. 预处理(Preprocessor) 2. 查询优化器(Optimizer) 3. 执行器…...
【Go语言基础【13】】函数、闭包、方法
文章目录 零、概述一、函数基础1、函数基础概念2、参数传递机制3、返回值特性3.1. 多返回值3.2. 命名返回值3.3. 错误处理 二、函数类型与高阶函数1. 函数类型定义2. 高阶函数(函数作为参数、返回值) 三、匿名函数与闭包1. 匿名函数(Lambda函…...
JavaScript 数据类型详解
JavaScript 数据类型详解 JavaScript 数据类型分为 原始类型(Primitive) 和 对象类型(Object) 两大类,共 8 种(ES11): 一、原始类型(7种) 1. undefined 定…...

mac 安装homebrew (nvm 及git)
mac 安装nvm 及git 万恶之源 mac 安装这些东西离不开Xcode。及homebrew 一、先说安装git步骤 通用: 方法一:使用 Homebrew 安装 Git(推荐) 步骤如下:打开终端(Terminal.app) 1.安装 Homebrew…...

STM32HAL库USART源代码解析及应用
STM32HAL库USART源代码解析 前言STM32CubeIDE配置串口USART和UART的选择使用模式参数设置GPIO配置DMA配置中断配置硬件流控制使能生成代码解析和使用方法串口初始化__UART_HandleTypeDef结构体浅析HAL库代码实际使用方法使用轮询方式发送使用轮询方式接收使用中断方式发送使用中…...