void () { DisposableWrapperList<String> l = new DisposableWrapperList<>(); Disposable d = Disposer.newDisposable(); l.add("a", d); l.add("b", d); l.add("c", d); l.add("d", d); StringBuilder buf = new StringBuilder(); for (String s : l) { buf.append(s); if (s.equals("b")) { Disposer.dispose(d); // Remove all elements from the list but not from the iterator. } } assertEquals("abcd", buf.toString()); assertTrue(l.isEmpty()); }