zoukankan      html  css  js  c++  java
  • guava set,map 的交集, 并集, 差集

    {// set的交集, 并集, 差集
        HashSet<Integer> setA = Sets.newHashSet(1, 2, 3, 4, 5);
        HashSet<Integer> setB = Sets.newHashSet(4, 5, 6, 7, 8);
        //并集
        Sets.SetView<Integer> union = Sets.union(setA, setB);
        log.info("union:" + union);
        //差集 setA-setB
        Sets.SetView<Integer> difference = Sets.difference(setA, setB);
        log.info("difference:" + difference);
        //交集
        Sets.SetView<Integer> intersection = Sets.intersection(setA, setB);
        log.info("intersection:" + intersection);
    }
    
    {//map的交集,并集,差集
        HashMap<String, Integer> mapA = Maps.newHashMap();
        mapA.put("a", 1);
        mapA.put("b", 2);
        mapA.put("c", 3);
        HashMap<String, Integer> mapB = Maps.newHashMap();
        mapB.put("b", 20);
        mapB.put("c", 3);
        mapB.put("d", 4);
        MapDifference<String, Integer> mapDifference = Maps.difference(mapA, mapB);
        //mapA 和 mapB 相同的 entry
        System.out.println(mapDifference.entriesInCommon());
        //mapA 和 mapB key相同的value不同的 entry
        System.out.println(mapDifference.entriesDiffering());
        //只存在 mapA 的 entry
        System.out.println(mapDifference.entriesOnlyOnLeft());
        //只存在 mapB 的 entry
        System.out.println(mapDifference.entriesOnlyOnRight());
    }
  • 相关阅读:
    复制某文件夹及其子文件夹中的一定大小的文件
    一个简单的查询脚本
    写一个交互的脚本
    nginx+php5.6.12+discuz
    curl 错误
    python 交互界面tab补全
    uwsgi.xml
    supervisorctl
    认识nginx配置文件
    nginx+uwsgi+django 配置3
  • 原文地址:https://www.cnblogs.com/ooo0/p/15010407.html
Copyright © 2011-2022 走看看