Resolving ConcurrentModificationException when deallocating objects iteratively

public static void main(String[] args) {
    Collection<Integer> l = new ArrayList<>();

    for (int i = 0; i < 10; ++i) {
        l.add(2);
        l.add(3);
        l.add(7);
    }

    for (int i : l) {
        if (i == 3) {
            l.remove(i);
        }
    }

    System.out.println(l);
}


I am using some arbitary collection data structure, wherein after the processing, I am trying to release the associated elements and deallocate the memory accordingly. This is my main() function and i have no multiple threads running and accessing same set of variables, but still i am receiving error as

Exception in thread "main" java.util.ConcurrentModificationException

If this has some issues or this is not the correct method for removing the elements from a collection, pls guide me to remove item from the collection iteratively without getting this exception.