EVALUATION
While this might have been a reasonable thing to put into the Collection interface, it is far too late to add methods to that interface. It might, however, be reasonable to add a "generic algorithm" to the java.util.Collections class. It's not at all hard to write this method, but it might be a worthwhile convenience (if the need is common enough).
Incidentally, the proposed workaround, while correct, may be inefficient; it's probably faster to iterate over the shorter collection and stop as soon as you find an element that's contained in the larger collection. (There maybe some cases where the proposed workaround is faster, but I suspect that it's rare.)
joshua.bloch@Eng 2000-06-28
|