Java ArrayList在遍历时删除元素

news2024/10/7 8:26:47

文章目录

  • 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");

    // 遍历 ok
    list.stream().forEach(System.out::println);

    for (int i = 0; i < list.size(); i++) {

        // 报异常:UnsupportedOperationException
        list.add("haha");

        // 报异常:UnsupportedOperationException
        list.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中的subList
                    Iterator<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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1341583.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Qt(二):使用udp发送与接收图片

使用Qt来通过UDP协议发送和接收图片可以分为几个步骤。以下是一个基本的指南&#xff1a; 发送图片准备图片数据&#xff1a;首先&#xff0c;你需要将图片转换为可以在网络上传输的数据格式。通常&#xff0c;这涉及到将图片转换为字节数组。设置UDP套接字&#xff1a;在Qt中…

Go 泛型之泛型约束

Go 泛型之泛型约束 文章目录 Go 泛型之泛型约束一、引入二、最宽松的约束&#xff1a;any三、支持比较操作的内置约束&#xff1a;comparable四、自定义约束五、类型集合&#xff08;type set&#xff09;六、简化版的约束形式七、约束的类型推断八、小结 一、引入 虽然泛型是…

水果软件2024FL Studio21.3mac苹果中文版

FL STUDIO21发布&#xff0c;提供您一直在等待的出色工作流程功能。通过新效果、多个播放列表曲目选择和无所畏惧的撤消一切编辑&#xff0c;将您的音乐带入2024年。FL Studio21中文完整版是一个功能齐全、开放式架构的PC音乐创作和制作环境。它具有基于音乐音序器的图形用户界…

uniapp:实现手机端APP登录强制更新,从本地服务器下载新的apk更新,并使用WebSocket,实时强制在线用户更新

实现登录即更新&#xff0c;或实时监听更新 本文介绍的是在App打开启动的时候调用更新&#xff0c;点击下方链接&#xff0c;查看使用WebSocket实现实时通知在线用户更新。 uniapp&#xff1a;全局消息是推送&#xff0c;实现app在线更新&#xff0c;WebSocket&#xff0c;ap…

白话机器学习的数学-1-回归

1、设置问题 投入的广告费越多&#xff0c;广告的点击量就越高&#xff0c;进而带来访问数的增加。 2、定义模型 定义一个函数&#xff1a;一次函数 y ax b &#xff08;a 是斜率、b 是截距&#xff09; 定义函数&#xff1a; 3、最小二乘法 例子&#xff1a; 用随便确定的参…

常见HTTP 500错误发生原因及解决办法剖析

​  对于网站运营者来说&#xff0c;提到500内部服务器错误并不陌生。互联网行业对它的称呼有好几种&#xff0c;如“500内部服务器错误”、“HTTP 500 - 内部服务器错误”、“临时错误 (500)”、“内部服务器错误”。尽管叫法不同&#xff0c;但根本问题是相同的。 目前&…

【Shell编程练习】通过位置变量创建 Linux 系统账户及密码

系列文章目录 输出Hello World 系列文章目录位置变量代码实现运行结果 位置变量 位置变量将以数字方式对变量进行命名&#xff0c;可将命令行参数的值存储到脚本中。要从命令行、函数或脚本执行等处传递参数时&#xff0c;就需要在 Shell 脚本中使用位置参数变量。下表为常用…

git unable to create temporary file: No space left on device(git报错)

1.问题 1.1 vscode中npm run serve跑项目的时候&#xff0c;进度达到95%的时候一直卡着无进度&#xff1b; 1.2 git命令提交代码报错&#xff1b; 2.具体解决 这个错误通常表示你的磁盘空间已经满了&#xff0c;导致 Git 无法在临时目录中创建文件。2.1 清理磁盘空间&#xf…

硅像素传感器文献调研(五)

写在前面之文献检索 —————————————————————————————————————————— 首先感慨一下sci-hub强大的检索能力。这篇论文在学校的数据库都没有搜到 来源是上篇论文的引用部分&#xff0c;截图如下&#xff1a; 先在谷歌学术镜像找到了&a…

数据结构 day6 栈+队列+二分查找+插入排序

插入排序 #include <stdio.h> #include<string.h> #include<stdlib.h> int main(int argc, const char *argv[]) {int a[]{41,50,66,38,32,49,18};int nsizeof(a)/sizeof(a[0]);int i,j,t;for(i1;i<n;i){int ta[i];for(ji-1;j>0;j--){if(t<a[j]){a…

flutter学习-day21-使用permission_handler进行系统权限的申请和操作

文章目录 1. 介绍2. 环境准备2-1. Android2-2. iOS 3. 使用 1. 介绍 在大多数操作系统上&#xff0c;权限不是在安装时才授予应用程序的。相反&#xff0c;开发人员必须在应用程序运行时请求用户的许可。在 flutter 开发中&#xff0c;则需要一个跨平台(iOS, Android)的 API 来…

跨境电商卖家一般用海外云手机做什么?

近些年&#xff0c;海外云手机在跨境电商领域已经逐渐流行开来&#xff0c;但是对于许多人来说海外云手机还是比较陌生&#xff0c;它有什么作用&#xff1f;它可以用于哪些场景&#xff1f;在本文中&#xff0c;我们将详细跨境电商卖家一般是怎样使用海外云手机的。 1. 海外网…

算法导论复习(七) 动态规划

动态规划一般用来求解最优化问题 设计一个动态规划算法一般有以下四步&#xff1a; 描述一个最优解的结构特征。递归地定义最优解的值。计算最优解的值&#xff0c;通常采用自底向上的方法。利用计算出的信息构造出一个最优解。 钢条切割问题 体现了动态规划的一个重要性质&a…

如何开发一个google插件(二)

前言 在上一篇文章如何开发一个google插件(一)里主要介绍了google插件的基本结构。 在这篇文章中主要结合reactwebpack进行一个代码演示&#xff0c;源码地址&#xff1a;源码地址 下载源码后打开浏览器的扩展程序管理->加载已解压的扩展程序&#xff0c;即可调试插件 此…

软件测试/测试开发丨学习笔记之Python运算符

运算符的作用 Python基础语法的内容通常表示不同数据或变量之间的关系 算数运算符 运算符描述加-减*乘/除%取模**幂//取整除 取模与取余区别 概念上&#xff1a;取模是计算机术语&#xff0c;取余属于数学概念&#xff1b; 结果上&#xff1a;当同号的两个数相除&#xff…

软件测试/测试开发丨Python内置库学习笔记

内置库 一、内置库OS 1、os概述 os: Operating Systemos 模块的常用功能跨平台的差异 2、os使用 导入 os 模块查看 os 模块使用文档 help(os)dir(os) import os# 查看os模块说明文档 help(os)# 查看os模块的属性和方法 print(dir(os))3、os 常用方法 &#xff08;1&…

浅谈WPF之控件模板Control Template和数据模板Data Template

WPF不仅支持传统的Windows Forms编程的用户界面和用户体验设计&#xff0c;同时还推出了以模板为核心的新一代设计理念。在WPF中&#xff0c;通过引入模板&#xff0c;将数据和算法的“内容”和“形式”进行解耦。模板主要分为两大类&#xff1a;数据模板【Data Template】和控…

仪表盘、数据分析新增分享功能及应用服务下新增服务实例菜单

近期&#xff0c;博睿数据根据一体化智能可观测平台 Bonree ONE 产品本身&#xff0c;以及用户反馈进行持续的更新和优化。以下为 Bonree ONE 产品功能更新报告第03期内容&#xff0c;更多探索&#xff0c;未完待续。 本次迭代的更新集中在平台的仪表盘、数据分析新增分享功能&…

JS + CSS 实现高亮关键词(不侵入DOM)

之前在做关键词检索高亮功能的时候&#xff0c;研究了下目前前端实现高亮的几种方式&#xff0c;第一就是替换dom元素实现高亮&#xff0c;第二就是利用浏览器新特性Css.highlights结合js选区与光标与CSS高亮伪类实现&#xff0c;实现功能如下&#xff1a; 一、页面布局 一个…

文献速递:人工智能医学影像分割---高效的MR引导CT网络训练,用于CT图像中前列腺分割

01 文献速递介绍 如今&#xff0c;根据国家癌症研究所的报告&#xff0c;美国约有9.9%的男性患有前列腺癌。1 此外&#xff0c;根据美国癌症协会的数据&#xff0c;预计2019年将有174,650个新病例被诊断出前列腺癌&#xff0c;与此同时大约有31,620名男性将死于前列腺癌。因此…