Java List Replace replace(final List list, final T newElement, final int index)

Here you can find the source of replace(final List list, final T newElement, final int index)

Description

replace

License

Open Source License

Declaration

public static <T> void replace(final List<T> list, final T newElement, final int index) 

Method Source Code

//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;
    }
}

Related

  1. replace(final String source, final List search, final List repl)
  2. replace(List list, Object o, Object n)
  3. replace(List list, T element, List replacements)
  4. replace(List list, char target, char replacement)