Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2016 Timo Vesalainen <timo.vesalainen@iki.fi>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;
import java.util.Collections;

import java.util.List;

public class Main {
    /**
     * @deprecated Replace with Collections.addAll
     * Populates collection with items
     * @param <T>
     * @param collection
     * @param items 
     * @see java.util.Collections#addAll(java.util.Collection, java.lang.Object...) 
     */
    public static final <T> void populate(Collection<T> collection, T... items) {
        Collections.addAll(collection, items);
    }

    /**
     * Adds array members to list
     * @param <T>
     * @param list
     * @param array 
     */
    public static <T> Collection<T> addAll(Collection<T> list, T... array) {
        for (T item : array) {
            list.add(item);
        }
        return list;
    }

    /**
     * Add arrays members to list starting at index.
     * <p>
     * If list contains a,b,c,d and array 1,2,3. After addAll(2, list, array)
     * list contains a,b,1,2,3,c,d 
     * @param <T>
     * @param index
     * @param list
     * @param array 
     */
    public static <T> List<T> addAll(int index, List<T> list, T... array) {
        for (T item : array) {
            list.add(index++, item);
        }
        return list;
    }
}