The fastest way to do a collection subtraction
- by Tony
I have two Sets. Set<B> b is the subset of Set<A> a. they're both very huge Sets.
I want to subtract b from a , what's the best practice to do this common operation ?
I've written to many codes like this , and I don't think it's efficient. what's your idea ?
for(int i = 0 ; i < a.size(); i++) {
for (int j=0 ; j < b.size() ;j++) {
// do comparison , if found equals ,remove from a
break;
}
}
And I want to find an algorithm , not only applies to Sets, also works for Array.