Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether a map contains all contents of another map

I am trying to check whether a map contains all contents of another map. For example, I have a mapA which is a Map<String, List<String>> and the elements are:

"1" -> ["a","b"]
"2" -> ["c","d"]

another mapB which is also a Map<String, List<String>>, the elements are:

"1" -> ["a"]
"2" -> ["c","d"],

I want to create a function compare(mapA, mapB) which will return false in this case.

What is the best way to do this?

like image 906
Atwood Wang Avatar asked Apr 04 '17 20:04

Atwood Wang


1 Answers

Inside your compare(mapA, mapB) method, you can simply use:

return mapA.entrySet().containsAll(mapB.entrySet());
like image 51
Jacob G. Avatar answered Oct 26 '22 09:10

Jacob G.