How to convert an ArrayList containing Integers to primitive int array?

前端 未结 18 1588
情书的邮戳
情书的邮戳 2020-11-22 11:23

I\'m trying to convert an ArrayList containing Integer objects to primitive int[] with the following piece of code, but it is throwing compile time error. Is it possible to

18条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 11:37

    Next lines you can find convertion from int[] -> List -> int[]

       private static int[] convert(int[] arr) {
            List myList=new ArrayList();
            for(int number:arr){
                   myList.add(number);
                }
            }
            int[] myArray=new int[myList.size()];
            for(int i=0;i

提交回复
热议问题