Java List Value Add All addAll(int index, List list, T... array)

Here you can find the source of addAll(int index, List list, T... array)

Description

Add arrays members to list starting at index.

License

Open Source License

Parameter

Parameter Description
T a parameter
index a parameter
list a parameter
array a parameter

Declaration

public static <T> List<T> addAll(int index, List<T> list, T... array) 

Method Source Code

//package com.java2s;
/*//from   w ww.  j a v  a2 s  .  c  o  m
 * 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.List;

public class Main {
    /**
     * 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;
    }
}

Related

  1. addAll(ArrayList list, T[] array)
  2. addAll(final List list, final E... values)
  3. addAll(final List firstList, final List secondList)
  4. addAll(final List list, final T... elements)
  5. addAll(List dest, List src)
  6. addAll(List fromList, List toList)
  7. addAll(List list, E[] elements)
  8. addAll(List list, String[] array)