Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Consumes all the elements of the iterator and
     * returns a list containing them. The iterator is
     * then unusable
     *
     * @param it An iterator
     *
     * @return a list containing the elements remaining
     * on the iterator
     */
    public static <T> List<T> toList(Iterator<T> it) {
        List<T> list = new ArrayList<>();
        while (it.hasNext()) {
            list.add(it.next());
        }
        return list;
    }
}