I want to do exactly like this in java
the accepted answer is perfect.. ‘Except’ method… is there a equivalent of this in Java …
sure there isn’t in standard Java lib, but is there something in third party libs like apache ?
P.S I googled this .. coudn’t find anything
You want to find the elements of list
athat are not present in listb.How about:
That will remove all elements of
bfroma. Whatever’s left inais by definition something that wasn’t inb.If you can’t or don’t want to change
a, copy it and do theremoveAll()on the copy.And more generally, if your collection class in Java doesn’t support
removeAll(), then create a collection type that does support it fromaand do the remove on that new object.If the lists are large, you’ll probably want to create a
HashSetfromafor example, so the removals (i.e. the internal lookup part of doing a removal) can happen more efficiently than for aListsubtype.