我有2 List<Long> id = [2316, 2317, 2318]
和
List<Long> existingId = [1004, 1762, 1892, 1342, 1942, 2316]
我想在java中以编程方式知道有多少不匹配以及数字是多少,在本例中为2和2317,2318
以编程方式,我尝试了以下内容,但它始终以false为无限循环:
for(int i=0; i<webCrtIdListExisting.size(); i++){
System.out.println("#########" + webCrtIdListExisting.contains(webCrtIdListNightly));
}
答案 0 :(得分:0)
您可以尝试这样的事情:
Collection<Integer> id = Arrays.asList(2316, 2317, 2318);
Collection<Integer> existingId = Arrays.asList(1004, 1762, 1892, 1342, 1942, 2316);
Collection<Integer> similar = new HashSet<Integer>( id );
similar.removeAll( existingId );
System.out.println("Different:"+similar);
System.out.println("#of items that are differnt:"+similar.size());