How to efficiently compare Sets? [duplicate]
This question already has an answer here: What is the fastest way to compare two sets in Java? 9 answers Given two Sets: how to compare them efficiently in Java? (a) keep them as List s, sort them and compare them. ( Comparable ) (b) keep them as Set s and compare the hashCode of the Sets? background: many comparisons need to be done Sets are small (usually < 5 elements per set). The proper way to compare two sets is to use the equals method . I would not worry about performance unless you have proven that this is a part of your code that is causing performance issue (which I doubt). And