void () { List<String> seq = Arrays.asList("0", "1", "2", "3", "4"); LockFreeCopyOnWriteArrayList<String> my = (LockFreeCopyOnWriteArrayList<String>)ContainerUtil.createLockFreeCopyOnWriteList(seq); { Iterator<String> iterator = my.iterator(); try { iterator.remove(); fail("must not be able to remove before next() call"); } catch (NoSuchElementException ignore) { } } int size = my.size(); Iterator<String> iterator = my.iterator(); for (int i = 0; i < size; i++) { assertTrue(iterator.hasNext()); String next = iterator.next(); assertEquals(next, String.valueOf(i)); iterator.remove(); assertEquals(my.size(), size - i - 1); if (i == size - 1) { assertTrue(my.isEmpty()); } else { assertEquals(my.toArray()[0], String.valueOf(i + 1)); assertEquals(my.toString(), seq.subList(i + 1, seq.size()).toString()); } } try { iterator.remove(); fail("must not be able to double remove()"); } catch (NoSuchElementException ignore) { } }