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ÿ…...
《Qt C++ 与 OpenCV:解锁视频播放程序设计的奥秘》
引言:探索视频播放程序设计之旅 在当今数字化时代,多媒体应用已渗透到我们生活的方方面面,从日常的视频娱乐到专业的视频监控、视频会议系统,视频播放程序作为多媒体应用的核心组成部分,扮演着至关重要的角色。无论是在个人电脑、移动设备还是智能电视等平台上,用户都期望…...
FFmpeg 低延迟同屏方案
引言 在实时互动需求激增的当下,无论是在线教育中的师生同屏演示、远程办公的屏幕共享协作,还是游戏直播的画面实时传输,低延迟同屏已成为保障用户体验的核心指标。FFmpeg 作为一款功能强大的多媒体框架,凭借其灵活的编解码、数据…...
CMake基础:构建流程详解
目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...
页面渲染流程与性能优化
页面渲染流程与性能优化详解(完整版) 一、现代浏览器渲染流程(详细说明) 1. 构建DOM树 浏览器接收到HTML文档后,会逐步解析并构建DOM(Document Object Model)树。具体过程如下: (…...
华为OD机试-食堂供餐-二分法
import java.util.Arrays; import java.util.Scanner;public class DemoTest3 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint a in.nextIn…...
【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】
1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件(System Property Definition File),用于声明和管理 Bluetooth 模块相…...
智能AI电话机器人系统的识别能力现状与发展水平
一、引言 随着人工智能技术的飞速发展,AI电话机器人系统已经从简单的自动应答工具演变为具备复杂交互能力的智能助手。这类系统结合了语音识别、自然语言处理、情感计算和机器学习等多项前沿技术,在客户服务、营销推广、信息查询等领域发挥着越来越重要…...
视觉slam十四讲实践部分记录——ch2、ch3
ch2 一、使用g++编译.cpp为可执行文件并运行(P30) g++ helloSLAM.cpp ./a.out运行 二、使用cmake编译 mkdir build cd build cmake .. makeCMakeCache.txt 文件仍然指向旧的目录。这表明在源代码目录中可能还存在旧的 CMakeCache.txt 文件,或者在构建过程中仍然引用了旧的路…...
面向无人机海岸带生态系统监测的语义分割基准数据集
描述:海岸带生态系统的监测是维护生态平衡和可持续发展的重要任务。语义分割技术在遥感影像中的应用为海岸带生态系统的精准监测提供了有效手段。然而,目前该领域仍面临一个挑战,即缺乏公开的专门面向海岸带生态系统的语义分割基准数据集。受…...
并发编程 - go版
1.并发编程基础概念 进程和线程 A. 进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单位。B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。C.一个进程可以创建和撤销多个线程;同一个进程中…...
