void () { final LinkedHashMap<Integer, String> tested = new LinkedHashMap<>(); for (int i = 0; i < 10000; ++i) { tested.put(i, Integer.toString(i)); } Iterator<Integer> it = tested.keySet().iterator(); while (it.hasNext()) { final int i = it.next(); if (i % 2 == 0) { it.remove(); } } assertEquals(5000, tested.size()); it = tested.keySet().iterator(); for (int i = 1; i <= 9999; i += 2) { Assert.assertTrue(it.hasNext()); assertEquals(i, it.next().intValue()); } }