当前位置:网站首页>Record the pits where an error occurs when an array is converted to a collection, and try to use an array of packaging types for conversion
Record the pits where an error occurs when an array is converted to a collection, and try to use an array of packaging types for conversion
2022-08-02 01:41:00 【Can't think of Xiao Zhao】
When using array to collection, try to use the wrapper type array for conversion.
描述
- 使用Basic data types to create arrays的时候,When you want to turn it into a collection,It is equivalent to storing a reference in the collection.
- 使用The wrapper type creates an array,when converting it to a collection,A collection stores the values in an array
How to convert an array to a collection
Arrays.asList(数组);
The converted collection cannot be modified such as adding or deleting,否则会报错Collections.addAll(arrayList, strArray)
Arrays.stream(ints).boxed().collect(Collectors.toList());
代码示例
public class Test {
public static void main(String[] args) {
int[] arrInt = {
1, 2, 3, 2, 2, 3, 2, 3};
List<int[]> ints = Arrays.asList(arrInt);
System.out.println(ints);
Integer[] arrInteger = {
1, 2, 3, 2, 2, 3, 2, 3};
List<Integer> integers = Arrays.asList(arrInteger);
System.out.println(integers);
}
}
运行结果
边栏推荐
猜你喜欢
typescript34-class的基本使用
GO开发环境配置
html+css+php+mysql实现注册+登录+修改密码(附完整代码)
Two ways to pass feign exceptions: fallbackfactory and global processing Get server-side custom exceptions
Day115.尚医通:后台用户管理:用户锁定解锁、详情、认证列表审批
6-25漏洞利用-irc后门利用
华为5年女测试工程师离职:多么痛的领悟...
安全(2)
Navicat data shows incomplete resolution
C语言实验九 函数(一)
随机推荐
NFT到底有哪些实际用途?
力扣 1161. 最大层内元素和
flv.js解析与使用
typescript30-any类型
浅谈国产ERP的“横纵竖”三向发展态势
《自然语言处理实战入门》 基于知识图谱的问答机器人
牛顿定理和相关推论
Redis cluster mode
Huawei's 5-year female test engineer resigns: what a painful realization...
C语言实验七 二维数组程序设计
使用百度EasyDL实现厂区工人抽烟行为识别
fastjson详解
Kubernetes — 核心资源对象 — 存储
datax与datax-web安装部署
Pcie the inbound and outbound
制造企业数字化转型现状分析
Day.js 常用方法
电商库存系统的防超卖和高并发扣减方案
简单工厂模式
飞桨助力航天宏图PIE-Engine地球科学引擎构建