两个数组之间的差异 [英] differences between two arrays
本文介绍了两个数组之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
java中数组列表的交集/并集
您好,我有两个字符串数组.我想打印两个数组之间的差异.有没有针对此的 Java 方法?例如;
Hello I have two string arrays.I want to print differences between two arrrays.Is there any java method for this? For example;
String[ ] first={"A","B","C"};
String[ ] second={"C","B"};
并且结果必须是A".感谢所有评论.
and result must be "A". Thanks for all comments.
推荐答案
将数组转换为 Set
new HashSet<String>(Arrays.asList(array));
然后做
Set<String> commonOnes = biggerSet.retainAll(smallerSet);
biggerSet.removeAll(commonOnes).add(smallerSet.removeAll(commonOnes))
或使用番石榴 difference()
or use guava difference()
这篇关于两个数组之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文