Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class Main {
    /**
     * <P>This method converts an array into an ArrayList. (The reverse of a Collection.toArray() method).</P>
     *
     * @param array The array of objects we want within an ArrayList.
     * @return the collection of objects originally contained on the array parameter.
     */
    public static Collection<Object> toArrayList(Object[] array) {
        if (array != null && array.length > 0) {
            ArrayList<Object> result = new ArrayList<Object>(array.length);
            Collections.addAll(result, array);
            return result;
        }
        return null;
    }
}