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;

import java.util.List;

public class Main {
    public static <E> List<E> copyNullSafeList(Collection<? extends E> list) {
        if (list.isEmpty()) {
            return Collections.emptyList();
        }
        return Collections.unmodifiableList(copyNullSafeMutableList(list));
    }

    public static <E> ArrayList<E> copyNullSafeMutableList(Collection<? extends E> list) {
        if (list == null)
            throw new NullPointerException("list");

        ArrayList<E> result = new ArrayList<E>(list);
        for (E element : result) {
            if (element == null)
                throw new NullPointerException("element");
        }
        return result;
    }
}