differences between two arrays

arrays, java

Solution

Convert array to `Set<String>`

new HashSet<String>(Arrays.asList(array));

and do

Set<String> commonOnes = biggerSet.retainAll(smallerSet);
biggerSet.removeAll(commonOnes).add(smallerSet.removeAll(commonOnes))

or use guava `difference()`

Problem

Possible Duplicate: intersection/union of arraylists in 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"}; ``` and result must be "A". Thanks for all comments.

Original source

Related problems