且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 int[] 转换为 List在爪哇?

更新时间:2023-02-14 10:26:01

int[] 转换为 List as 没有捷径Arrays.asList 不处理装箱,只会创建一个 List 这不是你想要的.你必须制定一个实用方法.

There is no shortcut for converting from int[] to List<Integer> as Arrays.asList does not deal with boxing and will just create a List<int[]> which is not what you want. You have to make a utility method.

int[] ints = {1, 2, 3};
List<Integer> intList = new ArrayList<Integer>(ints.length);
for (int i : ints)
{
    intList.add(i);
}