for (Iterator<Cat> iterator = cats.iterator(); iterator.hasNext();) { Cat c= iterator.next();<---------------------------- iterator.remove(); } without this the code is not working if someone can help