I know the Union Find algorithm from Wikipedia, and can find small implementations of them, but does Java itself use a similar algorithm for its Set's? If so I'd prefer to use Java Sets without recoding the wheel...
Java's Set interface supports completely different operations (and is therefore appropriate for completely different use cases) that a Union Find structure.
AFAIK No, to create a union of two sets, the common approach is to copy one set and add all the elements of the second. (Or copy all the element of both sets to the same set) e.g.
Set<E> set1, set2;
Set<E> union = new HashSet<E>(set1);
union.addAll(set2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With