demo
CopyOnWriteArrayList<Integer> numbers
= new CopyOnWriteArrayList<>(new Integer[]{1, 3, 5, 8});
Iterator<Integer> iterator = numbers.iterator();
List<Integer> actualList = new ArrayList<Integer>();
while (iterator.hasNext()) {
actualList.add(iterator.next());
}
actualList.forEach(System.out::println);
CopyOnWriteArrayList<Integer> numbers
= new CopyOnWriteArrayList<>(new Integer[]{1, 3, 5, 8});
Iterator<Integer> iterator = numbers.iterator();
List<Integer> actualList = new ArrayList<Integer>();
iterator.forEachRemaining(actualList::add);
actualList.forEach(System.out::println);
CopyOnWriteArrayList<Integer> numbers
= new CopyOnWriteArrayList<>(new Integer[]{1, 3, 5, 8});
Iterator<Integer> iterator = numbers.iterator();
Iterable<Integer> iterable = () -> iterator;
List<Integer> actualList = StreamSupport
.stream(iterable.spliterator(), false)
.collect(Collectors.toList());
actualList.forEach(System.out::println);
CopyOnWriteArrayList<Integer> numbers
= new CopyOnWriteArrayList<>(new Integer[]{1, 3, 5, 8});
Iterator<Integer> iterator = numbers.iterator();
List<Integer> actualList = IteratorUtils.toList(iterator);
actualList.forEach(System.out::println);