@Jacob G提供的答案不适用于您的情况。仅当 中存在额外的(键、值)对时,它才有效。喜欢MapA
MapA = {"1" -> ["a","b"] "2" -> ["c","d"] }
和
MapB = {"1" -> ["a","b"] }.
你需要的是这个:
boolean isStrictlyDominate(LinkedHashMap<Integer, HashSet<Integer>> firstMap, LinkedHashMap<Integer, HashSet<Integer>> secondMap){
for (Map.Entry<Integer, HashSet<Integer>> item : secondMap.entrySet()) {
int secondMapKey = item.getKey();
if(firstMap.containsKey(secondMapKey)) {
HashSet<Integer> secondMapValue = item.getValue();
HashSet<Integer> firstMapValue = firstMap.get(secondMapKey) ;
if(!firstMapValue.containsAll(secondMapValue)) {
return false;
}
}
}
return !firstMap.equals(secondMap);
}
(如果你不想检查严格的统治,那么在最后的陈述中就是正确的)return
return