baidu_19694879
baidu_19694879
2016-03-23 07:54

android异常 ConcurrentModificationException()

15
  • iterator
  • android
  • hashmap
  • 异常

要进行的操作是,遍历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);
}

            }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答

为你推荐