The fastest way to do a collection subtraction

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2010-03-08T12:12:30Z Indexed on 2010/03/08 12:21 UTC
Read the original article Hit count: 337

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about Performance

Related posts about java