开发者社区> 问答> 正文

关于android异常 ConcurrentModificationException() 的问题

要进行的操作是,遍历map.判断key值是否存在。如果存在,,则this key对应的valuez增加一个list,否则的话,就重新再添加一组键值对,

private Map> modleLists() {
 List lists = new ArrayList();
 Map> maps = null;
 for (int i = 0; i < carInfoLists.size(); i++) {
 if (maps == null) {
 maps = new HashMap>();
 lists.add((carInfoLists.get(i)));
 maps.put(carInfoLists.get(i).getModleName(), lists);
 } else {
 Iterator>> it = maps.entrySet().iterator();
 while (it.hasNext()) {
 Entry> next = it.next();
 String key = next.getKey();
 if (carInfoLists.get(i).getModleName().equals(key)) {
 CarModle carModle = carInfoLists.get(i);
 maps.get(key).add(carModle);
 } else {
 lists.clear();
 lists.add(carInfoLists.get(i));
 maps.put(carInfoLists.get(i).getModleName(), lists);
 }
            }

展开
收起
爵霸 2016-03-10 08:32:02 2400 0
1 条回答
写回答
取消 提交回答
  • 在遍历maps的时候,又操作maps.put了

    lists.clear();
    lists.add(carInfoLists.get(i));
    maps.put(carInfoLists.get(i).getModleName(), lists);//在遍历内部在put是有问题的。
    2019-07-17 18:56:41
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载