Here you can find the source of intersectSet(Set extends Object> orig, Set extends Object> intersect)
Parameter | Description |
---|---|
orig | if null, return intersect |
public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect)
//package com.java2s; import java.util.Collections; import java.util.HashSet; import java.util.Set; public class Main { /**/*w w w. j ava 2 s . c o m*/ * @param orig * if null, return intersect */ public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect) { if (orig == null) return intersect; if (intersect == null || orig.isEmpty()) return Collections.emptySet(); Set<Object> set = new HashSet<Object>(orig.size()); for (Object p : orig) { if (intersect.contains(p)) set.add(p); } return set; } }