Here you can find the source of add(List
index
.
Parameter | Description |
---|---|
list | collection of elements |
index | specific index |
item | object to add. |
public static <E, T extends E> void add(List<E> list, int index, T item)
//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); } } }