Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find String Array Difference in Java

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?

like image 703
user268018 Avatar asked Apr 02 '26 03:04

user268018


1 Answers

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.

like image 106
Bart Kiers Avatar answered Apr 03 '26 18:04

Bart Kiers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!