Java List Union union(List list1, List list2, boolean duplicate)

Here you can find the source of union(List list1, List list2, boolean duplicate)

Description

union

License

Open Source License

Declaration

public static <T> List<T> union(List<T> list1, List<T> list2, boolean duplicate) 

Method Source Code


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

import java.util.*;

public class Main {

    public static <T> Set<T> union(Set<T> set1, Set<T> set2) {
        if (set1 == null || set2 == null) {
            return (set1 == null) ? new HashSet<T>(set2) : new HashSet<T>(set1);
        }/*from  w  ww. ja va 2s  . com*/
        Set<T> ret = new HashSet<T>(set1);
        ret.addAll(set2);
        return ret;
    }

    public static <T> List<T> union(List<T> list1, List<T> list2, boolean duplicate) {
        if (list1 == null || list2 == null) {
            return (list1 == null) ? new ArrayList<T>(list2) : new ArrayList<T>(list1);
        }
        List<T> ret;
        if (duplicate) {
            ret = new ArrayList<T>(list1);
            ret.addAll(list2);
        } else {
            Set<T> set = union(new HashSet<T>(list1), new HashSet<T>(list2));
            ret = new ArrayList<T>(set);
        }
        return ret;
    }
}

Related

  1. union(final List list1, final List list2)
  2. union(final List... lists)
  3. Union(List A, List B)
  4. union(List ls, List ls2)
  5. union(List byteList)
  6. union(List set1, List set2)
  7. union(List... lists)
  8. unionAdd(List vect, E obj)
  9. unionCreditList(List list)