I tried to debug program and it shows ConcurrentModificationException. I found out that error is in lanes 31-33 cause its tries to iterate and delete items at the same time. So i just wanted to ask why my foreach loop doesnt work? It should be working the same way as if i created iterator the long way, or not? For example: Iterator<String> iterator = map.values().iterator(); while(iterator.hasNext()){ String nextItem = iterator.next(); if(nextItem == something){ iterator.remove(); } } This should be the same as code below? for(String x : map.values()){ if(x == something){ map.remove(x); } } Is it the same or did i misunderstood this? I read it here that foreach loop is just short way of using iterator. https://codegym.cc/quests/lectures/questsyntax.level08.lecture02 This is the lane from article: "Java has shorthand notation for working with iterators. Following the pattern of while and for, one more special statement has been added: for each. It is also indicated using the keyword for." "The for-each statement is only used for working with collections and containers. It uses an iterator implicitly, but we only see the returned element."