---
title: "ConcurrentModificationException and a HashMap"
author: "wbj0110"
date: "2017-01-09T19:59:40Z"
tags: []
categories: ["编程语言"]
slug: "concurrentmodificationexception-and-a-hashmap"
draft: false
lastmod: "2017-01-09T19:59:40Z"
id: 2351535
url: "https://soledede.iteye.com/blog/2351535"
---

```java
Iterator it = map.entrySet().iterator();while(it.hasNext()){Entry item = it.next();
   map.remove(item.getKey());}
```

这种方法会出现错误

 

正确的删除办法是

Iterator it = map.entrySet().iterator();

   while (it.hasNext())

   {

      Entry item = it.next();

      it.remove();

   }