public static void main(String[] args) {List<Integer> integers = Arrays.asList(new Integer[]{1, 2, 3, 4});integers.add(5);integers.forEach(System.out::println);}

以上代码执行add等方法报错如下:
原因:Arrays.asList中的ArrayList集合来自(java.util.Arrays.ArrayList)包,并非来自(java.util.ArrayList)包,里面没有add等方法

解决方案:把Arrays.asList作为构造函数的参数传入ArrayList中,底层封装了转换代码

    public static void main(String[] args) {List<Integer> integers =new ArrayList<>( Arrays.asList(new Integer[]{1, 2, 3, 4}));integers.add(5);integers.forEach(System.out::println);}

Exception in thread “main“ java.lang.UnsupportedOperationException Arrays.asList中add报错相关推荐

  1. Exception in thread “main” java.lang.NoClassDefFoundError: freemarker/template/Configuration 代码生成报错

    mybatis-plus 代码生成机制很好用但是刚入门的新手总会遇到这个错误,原因是因为 mybatis-plus 项目 pom  虽然依赖了 <dependency><groupI ...

  2. Exception in thread “main“ java.lang.UnsupportedOperationException: Schema for type Any is not suppo

    报错信息 Exception in thread "main" java.lang.UnsupportedOperationException: Schema for type A ...

  3. list.add时报错:Exception in thread “main“ java.lang.UnsupportedOperationException

    用list.add()时报错: Exception in thread "main" java.lang.UnsupportedOperationExceptionat java. ...

  4. Exception in thread main java.lang.Error: 无法解析的编译问题: 方法 main 不能声明为 static;只能在静态类型或顶级类型中才能声明静态方法

    Exception in thread "main" java.lang.Error: 无法解析的编译问题: 方法 main 不能声明为 static:只能在静态类型或顶级类型中才 ...

  5. exception in thread main java.lang.noclassdeffounderror wrong name

    不含包层次的HelloWorld.java public class HelloWorld{ public static void main(String[] args) { System.out.p ...

  6. Exception in thread main java.lang.Error: Unresolved compilation problem

    初学java,使用eclipse编译时,可能会遇到如下图所示的编译错误(Exception in thread "main" java.lang.Error: Unresolved ...

  7. Exception in thread main java.lang.OutOfMemoryError: Java heap space

    在做大批量数据测试的时候,服务端初始化出现问题 测试规模,没个站2万点量测数据,整个数据超过20万,初始化过程中对量测数据初始化,按站分别初始化,但是初始化到总数据量10万的时候就会报内存溢出错误. ...

  8. Exception in thread main java.lang.IncompatibleClassChangeError: net/sf/cglib/core/DebuggingClassW

    问题: 今天在运行程序的时候报如下错误. 1. java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor 2. Exception i ...

  9. Eclipse 报 “Exception in thread main java.lang.OutOfMemoryError: Java heap space ”错误的解决办法

    Eclipse 报 "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space &qu ...

最新文章

  1. 2019年最新十篇「深度学习领域综述」论文
  2. 除了 k8s,留给 k 和 s 中间的数字不多了!
  3. sql 树状结构中知道 父节点与孙节点_集群环境中使用Zookeeper实现分布式幂等控制...
  4. 求求你!不要在网上乱拷贝代码了!一段网上找的代码突然炸了,项目出现大BUG...
  5. why object family error message is filtered out
  6. 二分法查找c语言程序_C语言的那些经典程序 第十四期
  7. 中国工程院出台“八不准” 为院士增选“划红线”
  8. Oracle中的AWR,全称为Automatic Workload Repository
  9. 50.本地VMware环境虚拟机的异地(Azure)容灾(上)
  10. VBA下载文件 使用WebBrowser 及 DoFileDownload
  11. 从零开始的单片机学习(二)
  12. 用js超简单判断图片地址是否存在(404问题)
  13. django 第一个应用
  14. Ngnix:防止恶意域名解析
  15. python代码的层次结构图_Python:父子层次结构的组合
  16. 引导未来:区块链经济七大设计原则
  17. Jenkins 添加侧边栏按钮链接 Sidebar Link插件
  18. 操作系统实验二——进程调度算法(FCFS、RR)
  19. 浅谈性能优化有哪些指标
  20. java中return不运行的情况_Java中try catch finally语句中含return语句的执行情况总结-编程陷阱...

热门文章

  1. UI设计插画素材|移动设备和网络屏幕
  2. ui kit模板,让新手设计师临摹提高!
  3. python列表添加元组_python 列表与元组的操作简介
  4. Linux内核 eBPF基础: 探索USDT探针
  5. VPP /什么是VPP?读这篇文章就够了
  6. OpenSubdiv:大规模并行CPU和GPU架构上实现高性能细分表面
  7. 终于知道为什么NVIDIA的linux驱动这么烂了,一波官方文档告诉你:Linux GPU Driver Developer’s Guide
  8. 聚类分析在用户行为中的实例_基于行为数据的消费信贷反欺诈方案
  9. thymeleaf随机数_SpringBoot2.0实现静态资源版本控制
  10. Dajngo之ajax(get和post)请求(亲测)