无法从对象转换为列表异常

时间:2017-09-14 06:01:09

标签: spring-mvc

List<myJavaClass> smallListnew = (List<myJavaClass>) i1.next();

上面的行导致错误,表示无法将对象类型转换为List<myJavaClass>类型。

以下是一些描述代码:

List<myJavaClass> i1=bigList.iterator();

大名单以下列方式包含许多小清单:

//here unique list contains some Long values without the duplicates that were being compared with the refreshJobCountList.
Iterator<Long> i=uniqueRefJobId.iterator();
while (i.hasNext()) {
    Long refreshJobID = i.next();
    List<myJavaClass> smallList = new ArrayList<>();

    for (myJavaClass details : refreshJobCountList) {
        if (refreshJobID.equals(details.getRefreshJobId())) {
            myJavaClass new_obj=new myJavaClass();
            new_obj.setCount(details.getCount());
            new_obj.setJobRunId(details.getJobRunId());
            new_obj.setRefreshJobId(details.getRefreshJobId());
            smallList.add(new_obj);
        }
    }

    bigList.addAll(smallList);  
}

1 个答案:

答案 0 :(得分:0)

而不是对数组进行类型转换。将小列表的元素添加到更大的列表中。使用.allAll()添加整个列表。