两个阵列之间的差异 [英] differences between two arrays
本文介绍了两个阵列之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/5283047/intersection-union-of-arraylists-in-java\">intersection/union在java中的ArrayList的
Possible Duplicate:
intersection/union of arraylists in java
您好,我有两个字符串arrays.I要打印这两arrrays.Is有任何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.
推荐答案
转换阵列设置&LT;串GT;
new HashSet<String>(Arrays.asList(array));
和做
Set<String> commonOnes = biggerSet.retainAll(smallerSet);
biggerSet.removeAll(commonOnes).add(smallerSet.removeAll(commonOnes))
或使用番石榴<一个href=\"http://docs.guava-libraries.google$c$c.com/git-history/v9.0/javadoc/com/google/common/collect/Sets.html#difference%28java.util.Set,%20java.util.Set%29\"相对=nofollow> 差()
or use guava difference()
这篇关于两个阵列之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文