Guest User

Untitled

a guest
Feb 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. Map<String, Object> myData = new HashMap<String, Object>();
  2. myData.put("A", 1);
  3. myData.put("B", 2);
  4. for(String key: myData.keySet())
  5. myData.remove(key);
  6.  
  7. This will throw an exception ConcurrentModificationException at runtime
  8.  
  9. Map<String, Object> myData = new ConcurrentHashMap<String, Object>();
  10. myData.put("A", 1);
  11. myData.put("B", 2);
  12. for(String key: myData.keySet())
  13. myData.remove(key);
Add Comment
Please, Sign In to add comment