Java List Value Add add(List list, int index, T item)

Here you can find the source of add(List list, int index, T item)

Description

Adds the given item to the list at specified index.

License

Apache License

Parameter

Parameter Description
list collection of elements
index specific index
item object to add.

Declaration

public static <E, T extends E> void add(List<E> list, int index, T item) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {
    /**//from  ww w  .ja  v a2 s .  c  o m
     * Adds the given item to the list at specified <code>index</code>.
     * <p/>
     * if <code>index</code> is greater than list size, it simply appends to the
     * list.
     * 
     * @param list
     *            collection of elements
     * @param index
     *            specific index
     * @param item
     *            object to add.
     */
    public static <E, T extends E> void add(List<E> list, int index, T item) {
        if (index < list.size()) {
            list.add(index, item);
        } else {
            list.add(item);
        }
    }
}

Related

  1. add(List list, int index, Object element)
  2. add(List valList, Object src)
  3. add(List list, E element)
  4. add(List result, ClassLoader loader)
  5. add(List list, E element)
  6. add(List list, int index, T item)
  7. add(List vector, int[] sparseVector)
  8. add(List list, Object[] array)
  9. add(List data, Object... values)

  10. HOME | Copyright © www.java2s.com 2016