public static <T> List<T> asList(Iterator<T> itr) {
        List<T> l = new ArrayList<>();
        if (itr != null) {
            while (itr.hasNext()) {
                l.add(itr.next());
            }
        }
        return l;
    }
public static < T > List < T > asList ( Iterator < T > itr ) { List < T > l = new ArrayList < > ( ) ; if ( itr != null ) { while ( itr . hasNext ( ) ) { l . add ( itr . next ( ) ) ; } } return l ; }
Returns an iterator as a list.

@param itr
an <code>Iterator</code>.
@return a <code>List</code>.