intersection two sets - Java java.util

Java examples for java.util:Set Intersection

Description

intersection two sets

Demo Code


//package com.java2s;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <T> Set<T> intersection(Set<T> set1, Set<T> set2) {
        Set<T> intersection = new HashSet<T>(set1);
        intersection.retainAll(set2);//  w  ww.ja  v  a2  s  .  c  o  m
        return intersection;
    }
}

Related Tutorials