import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by mazhuang on 2016/9/13.
 */
public class CollectionsOperate {
    public static void main(String[] args) {
        deleteFromMap();
    }

    public static void deleteFromMap() {
        Map<Integer, String> map = new HashMap<>();
        map.put(0, "Zero");
        map.put(1, "One");
        map.put(2, "Two");

        // ok, but not in traversal
        map.remove(1);

        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            // error! java.util.ConcurrentModificationException
            // map.remove(entry.getKey());
        }

        Iterator<Map.Entry<Integer, String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            // the only right way to remove element from collections when traversal
            iterator.next();
            iterator.remove();
        }
    }
}

@@ -14,64 +14,9 @@
 til.
-HashMap;%0Aimport java.util.Iterator;%0Aimport java.util.Map
+*
 ;%0A%0A/
@@ -159,24 +159,50 @@
 eFromMap();%0A
+        deleteFromList();%0A
     %7D%0A%0A    p
@@ -428,24 +428,115 @@
 remove(1);%0A%0A
+        // HashMap doesn't implements Interable interface, so cannot use for-each directly%0A
         for 
@@ -652,16 +652,29 @@
 xception
+ if not break
 %0A       
@@ -709,16 +709,38 @@
 Key());%0A
+            // break;%0A
         
@@ -1021,11 +1021,938 @@
  %7D%0A    %7D
+%0A%0A    public static void deleteFromList() %7B%0A        String%5B%5D array = %7B%22Hello%22, %22World%22%7D;%0A        List%3CString%3E list = Arrays.asList(array); // !!! Arrays$ArrayList%3C%3E, it's different from ArrayList%3C%3E%0A%0A        for (String str : list) %7B%0A            // error! java.lang.UnsupportedOperationException%0A            // Arrays$ArrayList%3C%3E.remove not implemented%0A            // list.remove(0);%0A        %7D%0A%0A        list = new ArrayList%3C%3E();%0A        list.add(%22Hello%22);%0A        list.add(%22World%22);%0A        list.add(%22Hi%22);%0A%0A        for (String str : list) %7B%0A            // error! java.util.ConcurrentModificationException if not break%0A            // list.remove(str);%0A            // break;%0A        %7D%0A%0A        Iterator%3CString%3E iterator = list.iterator();%0A        while (iterator.hasNext()) %7B%0A            iterator.next();%0A            // java.lang.IllegalStateException without iterator.next() before%0A            iterator.remove();%0A        %7D%0A    %7D
 %0A%7D%0A

Add remove from List method