Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /**
     * Gets a string list based on an iterator.
     * <p>
     * As the wrapped Iterator is traversed, an LinkedList of its string values is
     * created. At the end, the list is returned.
     * 
     * @param iterator the iterator to use, not null
     * @return a list of the iterator string contents
     * @throws NullPointerException if iterator parameter is null
     */
    public static List<String> toStringList(Iterator<?> iterator) {
        if (iterator == null) {
            throw new NullPointerException("Iterator must not be null");
        }
        List<String> list = new LinkedList<String>();
        while (iterator.hasNext()) {
            list.add(String.valueOf(iterator.next()));
        }
        return list;
    }
}