当前位置:网站首页>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
- Entry name ‘org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt’ collided
- Redis和MySQL数据一致性问题,有没有好的解决方案?
- kubernetes之服务发现
- 【ORB_SLAM2】SetPose、UpdatePoseMatrices
- 超大规模的产业实用语义分割数据集PSSL与预训练模型开源啦!
- go版本升级
- Oracle data to mysql FlinkSQL CDC to achieve synchronization
- Kubernetes — 核心资源对象 — 存储
- 6-25 Vulnerability Exploitation - irc Backdoor Exploitation
猜你喜欢
随机推荐
Local storage in Kubernetes
typescript30-any类型
canal realizes mysql data synchronization
datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法
S/4中究竟有多少个模块,你对这些模块了解多少
去经营企业吧
typescript29-枚举类型的特点和原理
PHP直播源码实现简单弹幕效果的相关代码
Flex layout in detail
H5页面调用微信授权获取code
Maxwell 一款简单易上手的实时抓取Mysql数据的软件
【图像融合】基于加权和金字塔实现图像融合附matlab代码
Flask gets post request parameters
flex布局中使用flex-wrap实现换行
About MySQL data insertion (advanced usage)
ofstream,ifstream,fstream读写文件
ECMAScript 2022 正式发布,有你了解过的吗?
iframe使用
Moonbeam与Project Galaxy集成,为社区带来全新的用户体验
datagrip连接mysql数据库









