Java 如何比较Long列表并返回匹配数
我有两个列表id=[231623172318]和 我想用java编程知道有多少不匹配,数字是多少,在本例中是2和23172318 以编程方式,我尝试了以下操作,但它转到了带有false always的无限循环:Java 如何比较Long列表并返回匹配数,java,Java,我有两个列表id=[231623172318]和 我想用java编程知道有多少不匹配,数字是多少,在本例中是2和23172318 以编程方式,我尝试了以下操作,但它转到了带有false always的无限循环: for(int i=0; i<webCrtIdListExisting.size(); i++){ System.out.println("#########" + webCrtIdListExisting.contains(webCrtIdListNightly)); }
for(int i=0; i<webCrtIdListExisting.size(); i++){
System.out.println("#########" + webCrtIdListExisting.contains(webCrtIdListNightly));
}
您可以尝试以下方法:
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());
这个问题看起来更像是一个工作指令,而不是一个问题。请通过显示您尝试过的内容并告诉我们您遇到的具体问题来改进它。哎呀..对不起,我的直接方法..我尝试了existingId.containsid,但它总是返回False。您看起来是在检查一个完整列表是否由另一个持有,而不是一个列表中的每个项目是否都在另一个列表中。酷。。。!collection.addAll可用于执行反向器
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());