1

我以List<List<String>>这种方式获取数据,

List<List<String>> repdata = [
    ["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"],
    ["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390","LC13"]]

我想特别删除内部列表中索引 14 处的值。

例如:在这个内部列表数据中

[["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"]]

我想删除FF20,

并且必须对 中的所有内部列表重复此操作List<List<String>> repdata

所以,我的决赛List<List<String>>是这样的,

List<List<String>> repdata = [
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","FF20","23840"],
["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390"]

实际上这List<List<String>> repdata is = criteria.list()来自休眠。就是这样改造的,

criteria.setResultTransformer(Transformers.TO_LIST);

我厌倦了这种方式删除,

List<List<String>> repdata = cr.list();
        for( List<String> list: repdata ){
            if( list.size() > 14){                              
                list.remove(14);
            }           
        }

但我不断得到UnsupportedOperationException

任何人都可以在这个问题上帮助我吗?

4

2 回答 2

1

虽然我没有足够的信息可用,但我怀疑返回的列表可能是固定大小的(或者无法以其他方式修改)。一个例子是我们从中得到的列表Arrays.asList不能添加/删除任何东西。我们不能在结构上修改这个列表。

解决方案可能是使用当前列表中的项目初始化列表实现。LinkedList 支持更快的删除并且可能是合适的。就像是:

List<String> list = new LinkedList<String>(Arrays.asList(your_list));

ArrayList如果它适合您的要求,您也可以使用。

于 2015-09-22T08:53:40.923 回答
0

我们不应该使用 List 的 remove 方法。相反,使用迭代器遍历它并使用迭代器自己的 remove 方法很有用。因为在使用 list 的 remove 方法时,会抛出 ConcurrentModificationException。

于 2015-09-22T10:20:10.143 回答