当前位置:网站首页>Judge the same value of two sets 𞓜 different values

Judge the same value of two sets 𞓜 different values

2022-06-26 03:54:00 Strong wind blows

  Take the same value


        // 1  Data one 
        List<Integer> ces1 = Arrays.asList(2, 3, 454, 5, 3);
        // 2  Data two 
        List<Integer> ces2 = Arrays.asList(2, 3, 43, 5, 32, 12);
        //  Store results 
        List list=new ArrayList();
        //  Create a map aggregate   The value of data one   treat as k To hold the 
        HashMap<Object,
                Object> map = new HashMap<>();
        //3  Traverse the value of test one 
        for (Integer e :ces1) {
            // 4 Deposit in map Collection 
            map.put(e, 1);
        }
        //5  Traverse   Test data 2   And map Of key  compare   If there is map Of k With test data 2 Value   It will be added to list Collection 
        for (Integer a:ces2){
            if (StringUtils.isNotBlank(Integer.toString(a))&& map.containsKey(a)){
                list.add(a);
            }
        }
        System.out.println(list);
    }

 

 

Different values

Only need to   map.containsKey(a) Change it to !map.containsKey(a)

 

原网站

版权声明
本文为[Strong wind blows]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260343254717.html