Here you can find the source of intersect(Set
Parameter | Description |
---|---|
a | First set to check |
b | Second set to check |
public static boolean intersect(Set<String> a, Set<String> b)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//from ww w . java 2 s . com * Checks that there is at least one matching item between the two sets. * * @param a First set to check * @param b Second set to check * @return Returns true if there is at lease one matching item between the two sets. */ public static boolean intersect(Set<String> a, Set<String> b) { for (String s : a) { if (b.contains(s)) return true; } return false; } public static boolean contains(Set<String> setTocheck, Set<String> mustHaveAllThese) { for (String s : mustHaveAllThese) {//iterate over all must have tags. if (!setTocheck.contains(s)) {//return immediately when item not found in setToCheck return false; } } return true; } }