美文网首页
int[] to Integer[]

int[] to Integer[]

作者: sherrysack | 来源:发表于2018-06-12 23:48 被阅读0次

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>();
for (int i : ints)
{
    intList.add(i);
}

Because this process is so stupid, I highly recommend not to do so in interview unless you are sure that what you are doing.

相关文章

网友评论

      本文标题:int[] to Integer[]

      本文链接:https://www.haomeiwen.com/subject/zjddeftx.html