Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2010 Oracle
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
 ******************************************************************************/

import java.util.ArrayList;
import java.util.Collections;

import java.util.List;

public class Main {
    public static <T> List<T> list(final T... entries) {
        switch (entries.length) {
        case 0: {
            return Collections.emptyList();
        }
        case 1: {
            return Collections.singletonList(entries[0]);
        }
        default: {
            final List<T> result = new ArrayList<T>();

            for (T entry : entries) {
                result.add(entry);
            }

            return result;
        }
        }
    }
}