Java List Union unionList(List la, List lb)

Here you can find the source of unionList(List la, List lb)

Description

union List

License

Apache License

Declaration

public static <T> List<T> unionList(List<T> la, List<T> lb) 

Method Source Code


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

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static <T> List<T> unionList(List<T> la, List<T> lb) {
        if (la == null) {
            la = new ArrayList<T>();
        }/*ww w.  java  2 s.  c  o  m*/
        if (lb == null) {
            lb = new ArrayList<T>();
        }
        List<T> cpLa = new ArrayList<T>();
        List<T> cpLb = new ArrayList<T>();
        cpLa.addAll(la);
        cpLb.addAll(lb);

        List<T> dumpList = new ArrayList<T>();
        for (T t : cpLa) {
            if (cpLb.contains(t)) {
                dumpList.add(t);
            }
        }
        cpLa.removeAll(dumpList);
        cpLb.removeAll(dumpList);
        cpLa.addAll(cpLb);
        return cpLa;
    }
}

Related

  1. union(List set1, List set2)
  2. union(List... lists)
  3. unionAdd(List vect, E obj)
  4. unionCreditList(List list)
  5. unionList( Collection col1, Collection col2)
  6. unionList(List list1, List list2)
  7. unionOfListOfLists( final Collection> collectionOfCollection)
  8. unionSeparator(List elements, String separator)