当前位置: 首页 > news >正文

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只能遍历&#xff0c;不能增加或删除元素2. java.util.ArrayList.SubList有实现add()、remove()方法3. 遍历集合时对元素重新赋值、对元素中的属性赋值、删除元素、新增元素3.1 普通for循环3.2 增强for循环3.3 forEach循环3.4 str…...

多模态大模型的前世今生

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

Android studio 花式按键

一、activity_main.xml代码&#xff1a; <?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实现异常的统一返回

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

2023-12-11 LeetCode每日一题(最小体力消耗路径)

2023-12-11每日一题 一、题目编号 1631. 最小体力消耗路径二、题目链接 点击跳转到题目位置 三、题目描述 你准备参加一场远足活动。给你一个二维 rows x columns 的地图 heights &#xff0c;其中 heights[row][col] 表示格子 (row, col) 的高度。一开始你在最左上角的格…...

PID为1的僵尸进程的产生及清理

父进程PID为1的僵尸进程通常是由init系统&#xff08;在Linux系统中通常是systemd&#xff09;产生的。这种情况通常发生在以下几种情况&#xff1a; 子进程结束&#xff0c;但其父进程没有正确地调用wait()或waitpid()系统调用来获取子进程的退出状态。在这种情况下&#xff0…...

043、循环神经网络

之——RNN基础 杂谈 第一个对于序列模型的网络&#xff0c;RNN。 正文 1.潜变量自回归模型 潜变量总结过去的信息&#xff0c;再和当前信息一起结合出新的信息。 2.RNN 循环神经网络将观察作为x&#xff0c;与前层隐变量结合得到输出 其中Whh蕴含了整个模型的时序信息&#xf…...

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连接上进行全双工通信的协议&#xff0c;允许客户端和服务器之间进行双向实时通信。 所谓心跳机制&#xff0c;就是在长时间不使用WebSocket连接的情况下&#xff0c;通过服务器与客户端之间按照一定时间间隔进行少量数据的通信来达到确认连接稳定的手…...

【unity学习笔记】捏人+眨眼效果+口型效果

一、vriod捏人 1.在vroidstudio软件中捏人 2.导出模型&#xff08;.vrm) 二、vrid导入unity的插件 1.在Git上搜索、打开univrm。 2.找到release页面找到合适的插件版本。&#xff08;VRM-0.116.0_0f6c&#xff09; 3.将univrm导入到工程中&#xff08;assets&#xff09;。 三…...

动态规划 | 最长公共子序列问题

文章目录 最长公共子序列题目描述问题分析程序代码复杂度分析 最短编辑距离题目描述问题分析程序代码复杂度分析 编辑距离题目描述输入格式输出格式 问题分析程序代码 最长公共子序列 题目描述 原题链接 给定两个字符串 text1 和 text2&#xff0c;返回这两个字符串的最长 公共…...

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开发过程中的幂等性问题

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

基于Docker的软件环境部署脚本,持续更新~

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

C#上位机与欧姆龙PLC的通信08----开发自己的通讯库读写数据

1、介绍 前面已经完成了7项工作&#xff1a; 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多线程模式单线程处理方式多线程处理方式 为什么要开启多线程&#xff1f;充分利用多核CPU提高网络I/O效率响应现代应用需求 多线程实现启用多线程 最后总结 背景介绍 在Redis 6.0版本中&#xff0c;…...

simulink代码生成(六)——多级中断的配置

假如系统中存在多个中断&#xff0c;需要合理的配置中断的优先级与中断向量表&#xff1b;在代码生成中&#xff0c;要与中断向量表对应&#xff1b;中断相关的知识参照博客&#xff1a; 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绘画

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

在FC中手工创建虚拟机模板

1、Linux去除个性化信息 &#xff08;1&#xff09;编辑网卡配置文件&#xff0c;只保留以下内容&#xff08;以RHEL 7为例&#xff09; &#xff08;2&#xff09;清除主机密钥信息&#xff08;开机会自动生成&#xff09; &#xff08;3&#xff09;清除Machine ID&#xff…...

OpenSSL provider

提供者 标准提供者默认提供者传统提供者FIPS 提供者基本提供者空提供者加载提供者 标准提供者 提供者是算法实现的容器。每当通过高级别 API 使用加密算法时&#xff0c;都会选择一个提供者。实际上是由该提供者实现执行所需的工作。OpenSSL 自带了五个提供者。在未来&#…...

pandas处理双周数据

处理文件题头格式 部门名称 年度名称 季节名称 商品名称 商品代码 品牌名称 品类名称 颜色名称 商店名称 0M 1L 1XL 27 28 29 2XL 30 31 32 33 3XL 4XL 5XL 6XL S 均1.导入包 导入源 pip install openpyxl -i https://pypi.doubanio.com/simple pip install pandas -i https…...

2023结婚成家,2024借势起飞

您好&#xff0c;我是码农飞哥&#xff08;wei158556&#xff09;&#xff0c;感谢您阅读本文&#xff0c;欢迎一键三连哦。 &#x1f4aa;&#x1f3fb; 1. Python基础专栏&#xff0c;基础知识一网打尽&#xff0c;9.9元买不了吃亏&#xff0c;买不了上当。 Python从入门到精…...

linux SHELL语句

shell编程 shell编程 一、初识shell 程序 语言 编程语言 自然语言 汉语 英语 计算机语言 c语言cjava php python go shell 编译型语言 c c java解释型语言 php python bash (不能闭源&#xff0c;开发难度低) 编译型语言:运行编译型语言是相对于解释型语言存在的&#xff…...

音频修复和增强软件:iZotope RX 10 (Win/Mac)中文汉化版

iZotope RX 是一款专业的音频修复和增强软件&#xff0c;一直是电影和电视节目中使用的行业标准音频修复工具&#xff0c;iZotope能够帮助用户对音频进行制作、后期合成处理、混音以及对损坏的音频进行修复&#xff0c;再解锁更多功能之后还能够对电影、游戏、电视之中的音频进…...

复试 || 就业day03(2023.12.29)算法篇

文章目录 前言同构字符串存在重复元素有效的字母异位词丢失的数字单词规律 前言 &#x1f4ab;你好&#xff0c;我是辰chen&#xff0c;本文旨在准备考研复试或就业 &#x1f4ab;文章题目大多来自于 leetcode&#xff0c;当然也可能来自洛谷或其他刷题平台 &#x1f4ab;欢迎大…...

处理urllib.request.urlopen报错UnicodeEncodeError:‘ascii‘

参考&#xff1a;[Python3填坑之旅]一urllib模块网页爬虫访问中文网址出错 目录 一、报错内容 二、报错截图 三、解决方法 四、实例代码 五、运行截图 六、其他UnicodeEncodeError: ascii codec 问题 一、报错内容 UnicodeEncodeError: ascii codec cant encode charac…...

数据结构模拟实现LinkedList双向不循环链表

目录 一、双向不循环链表的概念 二、链表的接口 三、链表的方法实现 &#xff08;1&#xff09;display方法 &#xff08;2&#xff09;size方法 &#xff08;3&#xff09;contains方法 &#xff08;4&#xff09;addFirst方法 &#xff08;5&#xff09;addLast方法 …...

性能优化-如何提高cache命中率

本文主要介绍性能优化领域常见的cache的命中率问题&#xff0c;旨在全面的介绍提高cache命中率的方法&#xff0c;以供大家编写出性能友好的代码&#xff0c;并且可以应对性能优化领域的面试问题。 &#x1f3ac;个人简介&#xff1a;一个全栈工程师的升级之路&#xff01; &am…...

分布式【4. 什么是 CAP?】

什么是 CAP&#xff1f; C 代表 Consistency&#xff0c;一致性&#xff0c;是指所有节点在同一时刻的数据是相同的&#xff0c;即更新操作执行结束并响应用户完成后&#xff0c;所有节点存储的数据会保持相同。 A 代表 Availability&#xff0c;可用性&#xff0c;是指系统提…...

<软考高项备考>《论文专题 - 39采购管理(3) 》

3 过程2-实施采购 3.1 问题 4W1H过程做什么获取卖方应答、选择卖方并授予合同的过程作用&#xff1a;选定合格卖方并签署关于货物或服务交付的法律协议。本过程的最后成果是签订的协议&#xff0c;包括正式合同。为什么做实际进行采购谁来做组织中的职能部门或项目经理什么时…...

Java在SpringCloud中自定义Gateway负载均衡策略

Java在SpringCloud中自定义Gateway负载均衡策略 一、前言 spring-cloud-starter-netflix-ribbon已经不再更新了&#xff0c;最新版本是2.2.10.RELEASE&#xff0c;最后更新时间是2021年11月18日&#xff0c;详细信息可以看maven官方仓库&#xff1a;org.springframework.clou…...

前端 js 基础(1)

js 结果输出 &#xff08;点击按钮修改文字 &#xff09; <!DOCTYPE html> <html> <head></head><body><h2>Head 中的 JavaScript</h2><p id"demo">一个段落。</p><button type"button" onclic…...

Android : 使用GestureOverlayView进行手势识别—简单应用

示例图&#xff1a; GestureOverlayView介绍&#xff1a; GestureOverlayView 是 Android 开发中用于识别和显示手势的视图组件。它允许用户在屏幕上绘制手势&#xff0c;并且应用程序可以检测和响应这些手势。以下是关于 GestureOverlayView 的主要特点&#xff1a; 手势识别…...

API集群负载统计 (100%用例)C卷 (JavaPythonNode.jsC语言C++)

某个产品的RESTful API集合部署在服务器集群的多个节点上, 近期对客户端访问日志进行了采集,需要统计各个API的访问频次, 根据热点信息在服务器节点之间做负载均衡,现在需要实现热点信息统计查询功能。 RESTful API的由多个层级构成,层级之间使用/连接,如/A/B/C/D这个地址…...

小梅哥Xilinx FPGA学习笔记18——专用时钟电路 PLL与时钟向导 IP

目录 一&#xff1a;IP核简介&#xff08;具体可参考野火FPGA文档&#xff09; 二&#xff1a; 章节导读 三&#xff1a;PLL电路原理 3.1 PLL基本实现框图 3.2 PLL倍频实现 3.3 PLL分频实现 四: 基于 PLL 的多时钟 LED 驱动设计 4.1 配置 Clocking Wizard 核 4.2 led …...

低代码平台在金融银行中的应用场景

随着数字化转型的推进&#xff0c;商业银行越来越重视技术在业务发展中的作用。在这个背景下&#xff0c;白码低代码平台作为一种新型的开发方式&#xff0c;正逐渐受到广大商业银行的关注和应用。白码低代码平台能够快速构建各类应用程序&#xff0c;提高开发效率&#xff0c;…...

Css基础内容

<!DOCTYPE html> <html> <head> <meta charset"UTF-8" /> <title>CSS</title> <!-- <link rel"stylesheet" href"Html5与Css3\CSS\my.css"> --> <!-- link引入外部样式表&#xff1a;rel&…...

微服务(11)

目录 51.pod的重启策略是什么&#xff1f; 52.描述一下pod的生命周期有哪些状态&#xff1f; 53.创建一个pod的流程是什么&#xff1f; 54.删除一个Pod会发生什么事情&#xff1f; 55.k8s的Service是什么&#xff1f; 51.pod的重启策略是什么&#xff1f; 可以通过命令kub…...

连锁门店管理需要信息化系统

连锁门店管理的信息化系统可以提供以下功能&#xff0c;以满足连锁企业日常管理的需求&#xff1a; 1. 连锁线下收银&#xff1a;信息化系统可以提供线下收银功能&#xff0c;包括商品扫码、价格结算、支付方式选择等。通过系统记录每笔交易数据&#xff0c;方便对销售情况进行…...

UTF-8编码:打破字符编码的国界

UTF-8编码&#xff1a;打破字符编码的国界 大家好&#xff0c;我是免费搭建查券返利机器人赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天&#xff0c;让我们一同探讨编程世界中一项至关重要的技术——“UTF-…...

HTML进阶

列表、表格、表单 文章目录 列表、表格、表单01-列表无序列表有序列表定义列表 02-表格表格结构标签-了解合并单元格 03-表单input 标签input 标签占位文本单选框上传文件多选框下拉菜单文本域label 标签按钮 04-语义化无语义的布局标签有语义的布局标签 05-字符实体 01-列表 …...

基于策略模式和简单工厂模式实现zip、tar、rar、7z四种压缩文件格式的解压

推荐语 这篇技术文章深入探讨了基于策略模式和简单工厂模式实现四种常见压缩文件格式的解压方法。通过阅读该文章&#xff0c;你将了解到如何利用这两种设计模式来实现灵活、可扩展的解压功能&#xff0c;同时适应不同的压缩文件格式。如果你对设计模式和文件处理感兴趣或刚好…...

修改jenkins的目录(JENKINS_HOME)

默认JENKINS_HOME是/var/lib/jenkins/ 现要修改为/home/jenkins_data/jenkins 最开始 sudo cp -a /var/lib/jenkins/ /home/jenkins_data/ 然后如下操作&#xff1a; 1、首先 /etc/sysconfig/jenkins&#xff1a;jenkins配置文件&#xff0c;“端口”&#xff0c;“JENKIN…...

Bytebase:统一数据库 CI/CD 解决方案 | 开源日报 No.128

bytebase/bytebase Stars: 7.9k License: NOASSERTION Bytebase 是一个数据库 CI/CD 解决方案&#xff0c;为开发人员和 DBA 提供统一的工具来管理不同数据库系统的开发生命周期。其主要功能包括标准化操作流程、SQL 代码审查、GitOps 集成以及数据访问控制等。关键特性和核心…...

History对象常用方法

文章目录 一、什么是History对象二、使用History对象 一、什么是History对象 history 对象来保存浏览器历史记录信息&#xff0c;也就是用户访问的页面。浏览器的前进与后退功能本质上就是 history 的操作。history 对象记录了用户浏览过的页面&#xff0c;通过该对象提供的 A…...

修改源码,element的el-table合并,处理合并产生的hover样式问题

1、确认自己element-ui的版本号 2、此element-ui下的lib包是修改过hover样式的包,如何替换自己文件下的node_modules中的包 修改后将lib文件夹中文件替换你项目中/node_module/element-ui/Lib中的文件问题??如果替换开发环境中的node_module的包无法升级到测试环境,因为nod…...

IoT 物联网常用协议

物联网协议是指在物联网环境中用于设备间通信和数据传输的协议。根据不同的作用&#xff0c;物联网协议可分为传输协议、通信协议和行业协议。 传输协议&#xff1a;一般负责子网内设备间的组网及通信。例如 Wi-Fi、Ethernet、NFC、 Zigbee、Bluetooth、GPRS、3G/4G/5G等。这些…...

使用java备份和恢复SQLServer表数据

需求 近来工作中遇到一个问题&#xff0c;内网办公系统中的数据需要导出到外网中进行查询&#xff0c;外网的数据库中还有一些表存储外网的数据&#xff0c;因此无法使用全库备份恢复功能来满足需求。即只从内网数据库中导出若干表的内容至外网数据库的对应表。 其他解决方案…...

27 UVM queue

uvm_queue类构建一个动态队列&#xff0c;该队列将按需分配并通过引用传递。 uvm_queue类声明&#xff1a; class uvm_queue #( type T int ) extends uvm_object 1 uvm_queue class hierarchy 2 uvm_queue class Methods 3 UVM Queue Example 在下面的示例中&#xff0c;…...