Java Utililty Methods List Merge

List of utility methods to do List Merge

Description

The list of methods to do List Merge are organized into topic(s).

Method

voidmergeLists(List baseList, List newItems)
merges the entries from newItems into the baseList
this implementation does adopt items from the baseList to the newItems in the same order
- without creating a new list
- without touching existing entries (which should not be removed)

This implementation only works if .equals() of the type T is implemented in a proper way
for (int i = baseList.size() - 1; i >= 0; i--) {
    T entry = baseList.get(i);
    if (!newItems.contains(entry)) {
        baseList.remove(entry);
for (int i = 0; i < newItems.size(); i++) {
    T entry = newItems.get(i);
...
ListmergeLists(List copyTo, List copyFrom)
merge Lists
if (copyTo == null) {
    return copyFrom;
} else if (copyFrom != null && !copyFrom.isEmpty()) {
    for (T t : copyTo) {
        if (!copyFrom.contains(t)) {
            copyFrom.add(t);
    return copyFrom;
return copyTo;
voidmergeLists(List dest, List inserts)
merge Lists
for (T t : inserts) {
    if (!dest.contains(t)) {
        dest.add(t);
ListmergeLists(List listA, List listB, List listC)
merge Lists
List<T> returnList = new ArrayList<T>(listA);
returnList.addAll(listB);
returnList.addAll(listC);
return Collections.unmodifiableList(returnList);
ListmergeLists(Object oldValue, Object newValue, Object newValue2)
Returns a list which is 3 way merge.
if (!(oldValue instanceof List) || !(newValue instanceof List) || !(newValue2 instanceof List))
    throw new IllegalArgumentException("one of the parameters is not a list.");
List oldList = (List) oldValue;
List newList = (List) newValue;
List newList2 = (List) newValue2;
List resultList = new ArrayList();
resultList.addAll(newList2);
List removedInNewList = new ArrayList();
...
voidmergeOperations(List> list1, Set ops2)
Only smallest disjoint sets are retained
if (list1.size() == 0) {
    list1.add(ops2);
    return;
if (ops2 == null) {
    return;
Iterator<Set<T>> it = list1.iterator();
...
intmergeOrdered(List base, List elems)
Merges elems into base with respect to the sorting order.
if (elems.isEmpty()) {
    return base.size();
if (base.isEmpty()) {
    base.addAll(elems);
    return 0;
int basePos = 0;
...
Stringmergepath(List pieces, String separator)
mergepath
StringBuilder buf = new StringBuilder();
for (int i = 0; i < pieces.size(); i++) {
    if (i > 0)
        buf.append(separator);
    buf.append(pieces.get(i));
return buf.toString();
ListmergerList(List sources, List targets)
merger List
List<T> results = new ArrayList<T>();
if (sources != null && !sources.isEmpty()) {
    results.addAll(sources);
if (targets != null && !targets.isEmpty()) {
    results.addAll(targets);
return results;
...
voidmergeSpeakerList(List speaker_list)
merge Speaker List