Get set Difference - Java java.util

Java examples for java.util:Set Operation

Description

Get set Difference

Demo Code


//package com.java2s;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <A> Set<A> setDiff(Set<A> a, Set<A> b) {
        Set<A> set = new HashSet<A>();
        for (A x : a)
            if (!b.contains(x))
                set.add(x);// w  ww.j a  v  a2 s.co  m
        return set;
    }
}

Related Tutorials