UnsupportedOperationException异常
2024-10-21 23:29:03
看看下面的例子,这样输出什么呢?
public class test {
public static void main(String[] args) {
String arr = "ab,cb,ef";
List<String> list = Arrays.asList(arr);
System.out.print("原集合:" + list);
list.add("gh");
System.out.print("新增元素的集合:" + list);
}
}
结果:
这是因为asList这个api新建了一个内部类ArrayList,这个内部类继承了AbstractList类,AbstractList类的add方法会抛出UnsupportedOperationException异常。
解决方法,直接new一个ArrayList即可。
最新文章
- 细说ASP.NET Forms身份认证
- Oracle日期函数和循环总结
- 数据结构:JAVA_二叉数查找树基本实现(上)
- 胶囊碰撞体(CapsuleCollider)
- 为什么memset的第二个参数不把int替换成char
- c++ primer plus 习题答案(2)
- 用macports装了一份openssl
- C++ 最简单的日志类
- 7. VIM 系列 - 程序员利器(语法检测、代码块补全、symbol管理、函数跳转)
- Solr配置步骤
- 对Inode、Hard Link以及Soft Link的理解
- 马永亮(马哥) linux视频2018年版
- ztree插件异步加载 使用RESTEasy报错 Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
- vue页面传参和接参
- mysql 查询优化 ~ explain与索引失效
- MySQL 5.6版本内存占用过高的解决办法
- install scala &; spark env
- JS笔记—01
- kepware http接口 c语言 python
- malloc基本实现
热门文章
- Mybatis二级缓存(1)
- char 与 string 互转 byte与string互转 list<;string>;与string[]互转 char与byte互转
- sqlalchemy+pandas:错误 &#39;OptionEngine&#39; object has no attribute &#39;execute&#39;,&#39;str&#39; object has no attribute &#39;_execute_on_connection&#39;
- 第三周day2
- IDEA EduTools Plugin Learning Cause
- centos更改java的环境变量
- 谷歌Chrome浏览器网页中看视频出现绿屏、闪烁和花屏等显示问题解决方法
- unity整理
- 写于vue3.0发布前夕的helloworld之三
- 自定义jar包供ERP使用