Get asymmetric Difference between array and collection - Java java.util

Java examples for java.util:Collection to Array

Description

Get asymmetric Difference between array and collection

Demo Code


//package com.java2s;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static <E> Collection<E> asymmetricDifference(E[] c1,
            Collection<E> c2) {
        Set<E> result = new HashSet<E>();
        for (E elem : c1) {
            if (!c2.contains(elem)) {
                result.add(elem);//from   w  w  w .  j  a  va 2  s .  c o m
            }
        }
        return result;
    }
}

Related Tutorials