首页 > 其他分享 >集合10 - Exception

集合10 - Exception

时间:2023-01-04 11:44:35浏览次数:40  
标签:10 Exception map list put 集合 new TODO

Collection-Exception

public class _Exception {
    public static void main(String[] args) {
        //TODO Collection Exception

        //TODO ArrayList list = new ArrayList(-1);  => IllegalArgumentException 非法容量
        ArrayList list = new ArrayList(10);
        list.add("a");
        list.add("b");
        list.add("c");

        //TODO list.get(3); => IndexOutOfBoundsException 访问索引越界
        //如果访问的集合是数组,那么索引的范围是 0 到 数组长度-1
        //如果访问的集合是List,那么索引的范围是 0 到 数据长度-1  => 底层数组有空间但无数据的不能访问

        LinkedList list1 = new LinkedList();
        //TODO list1.getFirst(); => NoSuchElementException 访问数据不存在

        HashMap map = new HashMap();
        map.put("a","1");
        map.put("b","2");
        map.put("c","3");

        //TODO ConcurrentModificationException 遍历过程中修改数据 => 数据不一致 -- 迭代器解决
//        for (Object o : map.keySet()) {
//            if ("b".equals(o)) {
//                map.remove(o); 或 map.put
//            }
//
//            System.out.println(map.get(o));
//        }

    }
}

标签:10,Exception,map,list,put,集合,new,TODO
From: https://www.cnblogs.com/Ashen-/p/17024396.html

相关文章

  • centos.7.6.1810
    最近在玩国产化系统,采用华为国产服务器,但是系统依旧采用centos,费劲找了很多网址都没有想用的版本我这里是用centos7.6.1810版本,提供下载地址,可以参考下:https://archive.k......
  • 问题:django.template.exceptions.TemplateSyntaxError: 'staticfiles' is not a regis
     django使用swagger自动生成API文档时,报错  解决方法: 在settings.py里面配置一下以下代码'libraries':{'staticfiles':'django.templatetags.static'......
  • SoC低功耗问题定位及优化的10个思路
    在低功耗特性中,软件可能实现起来并没有那么难,从设计到实现的时间可能并不会耗时特别长,耗时最长的是后续的商用问题定位以及对功耗的优化,这些都是建立在一定的实战基础上才......
  • JAVA问题总结之27--创建100个文件
    JAVA问题总结之27–创建100个文件:packagejava9231;importjava.io.File;importjava.io.IOException;publicclassforCreateNFile{publicstaticvoidmain(String[]......
  • JAVA问题总结之22--Arraylist集合的操作
    JAVA问题总结之22--Arraylist集合的操作:packagecom.atguigu.java1;importjava.util.ArrayList;importjava.util.List;importorg.junit.Test;publicclassTestList{......
  • 集合9 - Arrays工具类
    Arrays工具类常用方法publicclassUtil{publicstaticvoidmain(String[]args){//TODOCollection工具类--方法常为静态,通过类名直接访问......
  • 集合8 - Iterator迭代器
    IteratorJavaIterator(迭代器)不是一个集合,它是一种用于访问集合的方法,可用于迭代ArrayList和HashSet等集合。迭代器it的三个基本操作是next、hasNext和remove。......
  • 集合6 - HashMap
    HashMapHash--Hash算法根据key计算hash函数来存放数据、处理冲突(链地址法-红黑二叉树)=>无序存储,重复丢弃Map--键值对<key,value>中key是唯一的,作为value的索引......
  • ​硬核来袭 | 2 万字 + 10 图带你手撕 STL 关联式容器源码
    本篇已同步收录GitHub仓库,这里有小贺的源码阅读笔记:https://github.com/rongweihe/CPPNotes/tree/master/STL-source-code-notes大家好,我是小贺。鸽了好久的 STL源码系......
  • 秋招之路-链表面试题集合(一)
    前言链表是最基本的数据结构,面试官也常常用链表来考察面试者的基本能力,链表的操作也离不开指针,指针又很容易导致出错。综合多方面的原因,链表题目在面试中占据着很重要的地位......