当前位置:网站首页>List集合转数组
List集合转数组
2022-06-28 12:56:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
在集合与数组互转的小问题
一、集合转数组的时候,集合提供了两种方法
1,toArray的不带参方法但是其返回值类型为Object
在进行强转的时候会报出java.lang.ClassCastException类转换异常
2,toArray的带参方法,在创建数组的时候指定数组的长度,最好与集合size保持一致,否则集合长度大于数组长度,原数组江北重置为null
如图,指定数组长度为集合长度
如图,指定数组长度小于集合长度
二、数组转集合
使用: Arrays.asList(数组);
asList返回的是一个Array的内部类,其并没有实现集合的方法,在对返回的集合进行增删查操作会出错
如图:
a1[0] = “toto”;//对原数组修改会影响转为的集合
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/150684.html原文链接:https://javaforall.cn
边栏推荐
- FineReport安装教程
- Go language learning notes - Gorm usage - database configuration, table addition | web framework gin (VII)
- 关于IP定位查询接口的测评Ⅰ
- Continuous integration practice of Baidu app based on pipeline as code
- UDP传输rtp数据包丢帧
- Jerry's SPI1 plug-in flash recording modification [part]
- 10万美元AI竞赛:寻找大模型做得“更烂”的任务
- async-validator. JS data verifier
- 一文抄 10 篇!韩国发表的顶级会议论文被曝抄袭,第一作者是“原罪”?
- ASP.NET CORE Study04
猜你喜欢
【MySQL从入门到精通】【高级篇】(三)MySQL用户的创建_修改_删除以及密码的设置
Login interface accesses and clears the token
【历史上的今天】6 月 28 日:马斯克诞生;微软推出 Office 365;蔡氏电路的发明者出生
SHAREit实力出众,登陆全球 IAP 实力榜 Top7
newest! Introduction and practical tutorial of point cloud processing based on open3d
JS class 并不只是简单的语法糖!
manjaro easyconnecy报错:libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
ASP. NET CORE Study03
group_ Concat learning and configuration
一文抄 10 篇!韩国发表的顶级会议论文被曝抄袭,第一作者是“原罪”?
随机推荐
Mathematical principle derivation of structured light phase shift method + multifrequency heterodyne
Which securities company is the best and safest? How to open an account is the safest
Ipetronik data acquisition equipment and softing q-vision software are committed to ADAS test scheme
从pdb源码到frame帧对象
Vs2012 VC creates a new blank window application
【云原生】自助报表和BI能做这么多事?
Jerry's wif interferes with Bluetooth [chapter]
ASP. NET CORE Study06
ASP.NET CORE Study01
Evaluation of IP location query interface I
group_ Concat learning and configuration
2. 01背包问题
Jerry's wif interferes with Bluetooth [chapter]
哪一个证券公司最好最安全 怎么办理开户最安全
Centos6.5 php+mysql MySQL library not found
企业源代码保密方案分享
高考失利進哈工大,畢業卻留校要當“探索者”,丁效:科研就是厚積薄發
证券账户开户哪家的费率低 怎么办理开户最安全
mysql数据库扫盲,你真的知道什么是数据库嘛
Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)