Java examples for java.util:Iterator
remove All from Iterator
//package com.book2s; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static void main(String[] argv) { Iterator iterator = java.util.Arrays.asList("asdf", "book2s.com") .iterator();// w ww. ja v a 2 s. c o m removeAll(iterator); } public static void removeAll(final Iterator<?> iterator) { while (iterator.hasNext()) { iterator.remove(); } } public static <E> List<E> asList( @SuppressWarnings("unchecked") final E... array) { List<E> list = new ArrayList<>(array.length); for (E element : array) { list.add(element); } return list; } public static <E> List<E> asList(final Iterator<? extends E> iterator) { List<E> list = new ArrayList<>(); while (iterator.hasNext()) { list.add(iterator.next()); } return list; } }