简体   繁体   中英

I have two hashmap HashMap<String,List<String>> in this format how to compare both the values are same or not with same keys

HashMap<String,List<String>> dPlatemap

HashMap<String,List<String>> ePlatemap

The map contains List of values

Your question "how to compare both the values are same or not with same keys" may need some clarification:

  1. If you want to check if both maps have the same keys, and each key has same values and order since it's an List, you can use dPlatemap.equals(ePlatemap)

  2. If you want to check if both maps have the same values, for a given key, add a small util method could help, sth. like that:

boolean checkEqual(Map<String, List<String>> dPlatemap, Map<String, List<String>> ePlatemap, String Key) {
    if (!dPlatemap.containsKey(key) && !ePlatemap.containsKey(key)) 
        return true;
    if (!dPlatemap.containsKey(key) || !ePlatemap.containsKey(key)) 
        return false;
    return  dPlatemap.get(key).equals(ePlatemap.get(key));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM