取两个map的交集,并将map1的值赋值给map2;

/**
     * 取两个Map集合的交集(将map1的值赋给resultMap)
     *
     * @param map1 (有值)
     * @param map2 (没值)
     * @return 两个集合的交集
     */
    public static Map getMapJiaoJi(Map map1, Map map2) {
        Set bigMapKey = map1.keySet();
        Set smallMapKey = map2.keySet();
        Set differenceSet = Sets.intersection(bigMapKey, smallMapKey);
        Map resultMap = Maps.newHashMap();
        for (String key : differenceSet) {
            resultMap.put(key, map1.get(key));
        }
        return resultMap;
    }

 

你可能感兴趣的:(取两个map的交集,并将map1的值赋值给map2;)