Here you can find the source of replace(final List
public static <T> void replace(final List<T> list, final T newElement, final int index)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.List; public class Main { public static <T> void replace(final List<T> list, final T newElement, final int index) { if (!isIndexOutOfBounds(list, index)) { list.remove(index);//from w ww .j a v a2 s . c o m list.add(index, newElement); } } public static <T> boolean isIndexOutOfBounds(final List<T> list, final int index) { return isNullList(list) || index >= 0 && index < list.size(); } public static boolean isNullList(final Collection<?> list) { return list == null; } }