Find String Array Difference in Java

user268018 picture user268018 · Feb 8, 2010 · Viewed 7.3k times · Source

I created two array variables: s1 and s2 s1 contains {ram,raju,seetha} s2 contains {ram}

I want to subtract the two arrays as sets, in order to get the following result:

raju seetha

How can I do this?

Answer

Bart Kiers picture Bart Kiers · Feb 8, 2010

If the elements in your array are unique, you could create a java.util.Set and do a removeAl(...). If they're not unique, go for a java.util.List instead.