gpt4 book ai didi

java - Arraylist 到 Array 的转换 - toArray() 函数推断类型不符合上限错误

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:38:44 25 4
gpt4 key购买 nike

这是代码sinplet:

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);

这是错误信息:

no suitable method found for toArray(int[]) method AbstractCollection.toArray(T#1[]) is not applicable (inferred type does not conform to upper bound(s) inferred: int upper bound(s): Object)

  where T#1,T#2 are type-variable...

最佳答案

原语和泛型不匹配。您需要 Integer[] 而不是 int[]

关于java - Arraylist 到 Array 的转换 - toArray() 函数推断类型不符合上限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26111397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com