当前位置:网站首页>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
边栏推荐
- 弹性盒子自动换行小Demo
- From simplekv to redis
- How to install SSL certificates in Microsoft Exchange 2010
- Centos6.5 php+mysql MySQL library not found
- flutter 系列之:flutter 中常用的 GridView layout 详解
- async-validator. JS data verifier
- newest! Introduction and practical tutorial of point cloud processing based on open3d
- . Net hybrid development solution 24 webview2's superior advantages over cefsharp
- 求职简历的书写技巧
- Unity WebGL移动端去除警告
猜你喜欢
随机推荐
Jerry's wif interferes with Bluetooth [chapter]
认识启动函数,找到用户入口
深入理解贝叶斯定理
同花顺上怎么进行开户啊, 安全吗
ASP.NET CORE Study04
Enterprise source code confidentiality scheme sharing
The Research Report of Analysys' 2022 China Banking privacy computing platform supplier strength matrix analysis' was officially launched
[MySQL from introduction to mastery] [advanced part] (III) creation of MySQL users_ Modification_ Delete and password settings
[cloud native] can self-service reports and Bi do so many things?
go template with... End traversal usage
Jerry's SPI1 plug-in flash recording modification [part]
flex布局中的align-content属性
专业英语历年题
移动Web实训DAY-1
Performance test-01-introduction
async-validator. JS data verifier
Why does CAD export PDF have no color
Hundreds of lines of code to implement a JSON parser
I ² C. SMBus, pmbus relationships
移动Web实训-flex布局测试题1








