Java Utililty Methods Iterator

List of utility methods to do Iterator

Description

The list of methods to do Iterator are organized into topic(s).

Method

ListconvertToList(Iterator iter)
convert To List
List<Double> list = new ArrayList<Double>();
while (iter.hasNext())
    list.add(iter.next());
return list;
Iteratorcopy(Iterator iterator)
copy
List<T> list = toList(iterator);
return list.iterator();
ListcopyIterator(Iterable iterable)
copy Iterator
Iterator<T> iterator = iterable.iterator();
List<T> copy = new ArrayList<T>();
while (iterator.hasNext())
    copy.add(iterator.next());
return copy;
ListcopyIterator(Iterator iter)
Iterator to List
List<T> copy = new ArrayList<T>();
while (iter.hasNext())
    copy.add(iter.next());
return copy;
ListcopyOf(Iterator elements)
copy Of
if (elements == null) {
    return null;
if (!elements.hasNext()) {
    return Collections.emptyList();
List<E> list = new ArrayList<>();
while (elements.hasNext()) {
...
Mapcount(Iterator thingsToCount)
count
Map<THING, Integer> countedThings = new HashMap<>();
while (thingsToCount.hasNext()) {
    THING thing = thingsToCount.next();
    if (countedThings.containsKey(thing)) {
        int count = countedThings.get(thing);
        countedThings.put(thing, count + 1);
    } else {
        countedThings.put(thing, 1);
...
intcountIterator(Iterator it)
count Iterator
int x = 0;
while (it.hasNext()) {
    it.next();
    x++;
return x;
MapcreateMap(Iterator iter)
create Map
boolean finished = false;
Map<String, String> m = new HashMap<String, String>();
while (iter.hasNext() && !finished) {
    String row = iter.next();
    if (row.startsWith("~")) {
        finished = true;
    } else {
        String[] tokens = row.split("\\^");
...
IteratorcreatePathIterator(String path)
Returns an iterator that iterates over the sub nodes of a path.
String tPath = path.startsWith("/") ? path.substring(1) : path; 
if (tPath.length() == 0)
    tPath = null;
final String aPath = tPath;
return new Iterator() {
    int prevIndex = 0;
    int curIndex = 0;
    String pathString = aPath;
...
IterablecreateSkipIterator(Iterable source, int count)
create Skip Iterator
List<S> list = createList();
Iterator<S> iterator = source.iterator();
try {
    while (count-- > 0)
        if (!moveNext(iterator))
            break;
    while (iterator.hasNext())
        list.add(iterator.next());
...