I found an algorithm containing a merge method (https://commons.apache.org/proper/commons-math/jacoco/org.apache.commons.math3.stat.clustering/DBSCANClusterer.java.html)
private <T> List<T> theirMerge(final List<T> one, final List<T> two) {
final Set<T> oneSet = new HashSet<T>(one);
for (T item : two) {
if (!oneSet.contains(item)) {
one.add(item);
}
}
return one;
}
What is the main benefit of using a HashSet
here?
My simpler implementation looks like this
private <T> List<T> myMerge (ArrayList<T> one, ArrayList<T> two){
for (T item: two) {
if(!one.contains(item)){
one.add(item);
}
}
return one;
}