Java – ArrayList to array conversion – toarray() function infers that the type does not meet the upper limit error

This is the code simplet:

Excel excel = new Excel();
ArrayList<Integer> a1=excel.readExcelSheet("C:\\Users\\Madhukar\\Desktop\\Employee.xls");
        System.out.println("Using Iterator");
        Iterator iterator = a1.iterator();
        while (iterator.hasNext()) {
       System.out.println(iterator.next());}
        int x=a1.size();
        int[] a3=new int[x];
        a3=a1.toArray(a3);

This is the error message:

Solution

Primitives and generics do not match You need an integer [] instead of an int []

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>