Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.List;
import java.util.Collection;
import java.util.Iterator;
import java.util.ArrayList;

public class Main {
    /**
     * Converts the given collection to a <code>java.util.List</code>.
     * @param collection The collection to convert to a list.
     * @return A <code>java.util.List</code> containing all of the elements from the
     *         supplied collection.
     */
    public static List toList(Collection collection) {
        if (collection instanceof List)
            return (List) collection;

        List list = new ArrayList();
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()) {
            list.add(iterator.next());
        }
        return list;
    }
}