How to convert int[] into List in Java?

后端 未结 20 2154
萌比男神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

    int[] arr = { 1, 2, 3, 4, 5 };
    
    List list = Arrays.stream(arr)     // IntStream
                                .boxed()        // Stream
                                .collect(Collectors.toList());
    

    see this

提交回复
热议问题