看看下面的例子,这样输出什么呢?

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即可。

最新文章

  1. 细说ASP.NET Forms身份认证
  2. Oracle日期函数和循环总结
  3. 数据结构:JAVA_二叉数查找树基本实现(上)
  4. 胶囊碰撞体(CapsuleCollider)
  5. 为什么memset的第二个参数不把int替换成char
  6. c++ primer plus 习题答案(2)
  7. 用macports装了一份openssl
  8. C++ 最简单的日志类
  9. 7. VIM 系列 - 程序员利器(语法检测、代码块补全、symbol管理、函数跳转)
  10. Solr配置步骤
  11. 对Inode、Hard Link以及Soft Link的理解
  12. 马永亮(马哥) linux视频2018年版
  13. 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.
  14. vue页面传参和接参
  15. mysql 查询优化 ~ explain与索引失效
  16. MySQL 5.6版本内存占用过高的解决办法
  17. install scala &amp; spark env
  18. JS笔记—01
  19. kepware http接口 c语言 python
  20. malloc基本实现

热门文章

  1. Mybatis二级缓存(1)
  2. char 与 string 互转 byte与string互转 list&lt;string&gt;与string[]互转 char与byte互转
  3. sqlalchemy+pandas:错误 &#39;OptionEngine&#39; object has no attribute &#39;execute&#39;,&#39;str&#39; object has no attribute &#39;_execute_on_connection&#39;
  4. 第三周day2
  5. IDEA EduTools Plugin Learning Cause
  6. centos更改java的环境变量
  7. 谷歌Chrome浏览器网页中看视频出现绿屏、闪烁和花屏等显示问题解决方法
  8. unity整理
  9. 写于vue3.0发布前夕的helloworld之三
  10. 自定义jar包供ERP使用