如何将 int[] 数组转换为 List? [英] How to convert an int[] array to a List?
本文介绍了如何将 int[] 数组转换为 List?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望这段代码显示 true
:
I expected this code to display true
:
int[] array = {1, 2};
System.out.println(Arrays.asList(array).contains(1));
推荐答案
Arrays.asList(array)
将产生 int[]
的单例列表.
The Arrays.asList(array)
will result in a singleton list of an int[]
.
如果将 int[]
更改为 Integer[]
,它会按预期工作.不知道这是否对你有帮助.
It works as you expect if you change int[]
to Integer[]
. Don't know if that helps you though.
这篇关于如何将 int[] 数组转换为 List?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文