当前位置:网站首页>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);
}
}
运行结果
边栏推荐
猜你喜欢
canal realizes mysql data synchronization
使用百度EasyDL实现厂区工人抽烟行为识别
Can't connect to MySQL server on 'localhost3306' (10061) Simple and clear solution
Test Cases: Four-Step Test Design Approach
mapbox使用教程
传统企业数字化转型需要经过几个阶段?
3 Month Tester Readme: 4 Important Skills That Impacted My Career
pcie inbound和outbound关系
typescript32-ts中的typeof
Reflex WMS中阶系列6:对一个装货重复run pick会有什么后果?
随机推荐
bool Frame::PosInGrid(const cv::KeyPoint &kp, int &posX, int &posY)
【图像融合】基于加权和金字塔实现图像融合附matlab代码
飞桨助力航天宏图PIE-Engine地球科学引擎构建
字节给我狠狠上了一课:危机来的时候你连准备时间都没有...
Entry name ‘org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt’ collided
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
云和恩墨:让商业数据库时代的价值在openGauss生态上持续繁荣
Byte taught me a hard lesson: When a crisis comes, you don't even have time to prepare...
Shell入门终章
大话西游无法登陆解决
FlinkSQL CDC实现同步oracle数据到mysql
GO GOPROXY代理设置
input禁止输入
PHP直播源码实现简单弹幕效果的相关代码
理解分布式系统中的缓存架构(下)
去经营企业吧
flyway的快速入门教程
Day116.尚医通:预约挂号详情 ※
6-25 Vulnerability Exploitation - irc Backdoor Exploitation
typescript29-枚举类型的特点和原理