当前位置:网站首页>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
边栏推荐
- ASP.NET CORE Study05
- async-validator.js數據校驗器
- 一款自动生成单元测试的 IDEA 插件,开发效率提升 70% 以上!
- The paging style flex is set to be displayed at the end (even if the number of pages is longer, there will be no line breaks at the end)
- 移动Web实训DAY-1
- STM32F1与STM32CubeIDE编程实例-矩阵键盘驱动
- Validateur async. Vérificateur de données JS
- 简历模板百度网盘自取
- Beginner level of attack and defense World Hello_ pwn
- Continuous integration practice of Baidu app based on pipeline as code
猜你喜欢

一种跳板机的实现思路

Vs2012 VC creates a new blank window application

腾讯汤道生:面向数实融合新世界,开发者是最重要的“建筑师”

pytorch基础

IPETRONIK数据采集设备携手Softing Q-Vision软件致力于ADAS测试方案

易观分析《2022年中国银行业隐私计算平台供应商实力矩阵分析》研究报告正式启动

Here comes Wi Fi 7. How strong is it?

The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
JS class is not just a simple syntax sugar!

1015.摘花生
随机推荐
async-validator.js数据校验器
After failing in the college entrance examination, he entered Harbin Institute of technology, but stayed in the university after graduation to be an "Explorer". Ding Xiao: scientific research is accum
华泰证券手机app下载 怎么办理开户最安全
The paging style flex is set to be displayed at the end (even if the number of pages is longer, there will be no line breaks at the end)
4年用户数破亿,孙哥带领波场再创新高
ASP. NET CORE Study09
Validateur async. Vérificateur de données JS
BUUCTF:[WUSTCTF2020]朴实无华
Hundreds of lines of code to implement a JSON parser
Vscode如何设置代码保存后自动格式化
Continuous integration practice of Baidu app based on pipeline as code
Implementation of fruit and vegetable mall management system based on SSM
百度APP 基于Pipeline as Code的持续集成实践
Microservice stability guarantee
go template with...end遍历用法
[MySQL from introduction to mastery] [advanced part] (III) creation of MySQL users_ Modification_ Delete and password settings
【云原生】自助报表和BI能做这么多事?
Can ArcGIS Pro directly connect PostgreSQL and edit layer elements
移动Web实训DAY-1
深入理解贝叶斯定理