Java List Replace replace(List list, T element, List replacements)

Here you can find the source of replace(List list, T element, List replacements)

Description

replace

License

Apache License

Declaration

static <T> List<? extends T> replace(List<? extends T> list, T element, List<T> replacements) 

Method Source Code


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

import java.util.ArrayList;

import java.util.List;

public class Main {
    static <T> List<? extends T> replace(List<? extends T> list, T element, List<T> replacements) {
        List<T> list2 = new ArrayList<T>(list.size() + replacements.size());
        for (T node : list)
            if (node != element)
                list2.add(node);//from w w  w. j  a  va2 s .  com
        list2.addAll(replacements);
        return list2;
    }

    static <T> List<T> add(List<T> list, T element) {
        final ArrayList<T> result = new ArrayList<T>(list.size() + 2);
        result.addAll(list);
        result.add(element);
        return result;
    }
}

Related

  1. replace(final List list, final T newElement, final int index)
  2. replace(final String source, final List search, final List repl)
  3. replace(List list, Object o, Object n)
  4. replace(List list, char target, char replacement)
  5. replace(List list, T from, T to)
  6. replace(String s, List replacementVars)
  7. replace(String sourceStr, List indexList, String replaceStr)