Java List Replace replaceOrAdd(List list, T object)

Here you can find the source of replaceOrAdd(List list, T object)

Description

replace Or Add

License

Open Source License

Declaration

public static <T> List<T> replaceOrAdd(List<T> list, T object) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    public static <T> List<T> replaceOrAdd(List<T> list, T object) {
        if (list == null || object == null)
            return list;
        int i = list.indexOf(object);
        if (i != -1) {
            list.remove(object);// ww w . j a v  a  2  s  .c om
            list.add(i, object);
        } else {
            list.add(object);
        }
        return list;
    }
}

Related

  1. replaceIgnoreList(String text)
  2. replaceInLines(List lines, String from, String to, int fromIndex, int toIndex)
  3. replaceInList(T a, T b, List list)
  4. replaceList(String v, String[] patterns, String[] values)
  5. replaceNpcId(final List npcListSqlLines, final int lineIndex, final int newNpcId, final boolean markAsGuess)
  6. replacePolUtilsName( final List npcListSqlLines, final int lineIndex, final String name)
  7. replacePositions(StringBuffer c, int origLength, String string, List positions)