merge two Collection - Android java.util

Android examples for java.util:Collection Merge

Description

merge two Collection

Demo Code


//package com.book2s;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static <T> ArrayList<T> merge(Collection<T> l1,
            Collection<T> l2, T toRemove) {
        ArrayList<T> al = union(l1, l2);
        al.remove(toRemove);//from  w  w  w  .j  a v  a2 s .c  o  m
        return al;
    }

    public static <T> ArrayList<T> union(Collection<T> l1, Collection<T> l2) {
        Set<T> s = new HashSet<>();
        s.addAll(l1);
        s.addAll(l2);
        return new ArrayList<>(s);
    }
}

Related Tutorials