How to convert int[] into List in Java?

后端 未结 20 2127
萌比男神i
萌比男神i 2020-11-22 06:18

How do I convert int[] into List in Java?

Of course, I\'m interested in any other answer than doing it in a loop, item by it

20条回答
  •  情歌与酒
    2020-11-22 06:31

    If you're open to using a third party library, this will work in Eclipse Collections:

    int[] a = {1, 2, 3};
    List integers = IntLists.mutable.with(a).collect(i -> i);
    Assert.assertEquals(Lists.mutable.with(1, 2, 3), integers);
    

    Note: I am a committer for Eclipse Collections.

提交回复
热议问题