Java Iterator copyOf(Iterator elements)

Here you can find the source of copyOf(Iterator elements)

Description

copy Of

License

Apache License

Declaration

public static <E> List<E> copyOf(Iterator<? extends E> elements) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static <E> List<E> copyOf(Iterator<? extends E> elements) {
        if (elements == null) {
            return null;
        }/*ww w . j a  v a2  s. c  o m*/

        if (!elements.hasNext()) {
            return Collections.emptyList();
        }

        List<E> list = new ArrayList<>();
        while (elements.hasNext()) {
            list.add(elements.next());
        }

        return Collections.unmodifiableList(list);
    }
}

Related

  1. convertToArray(Iterator iter)
  2. convertToList(Iterator iter)
  3. copy(Iterator iterator)
  4. copyIterator(Iterable iterable)
  5. copyIterator(Iterator iter)
  6. count(Iterator thingsToCount)
  7. countIterator(Iterator it)
  8. createMap(Iterator iter)
  9. createPathIterator(String path)