I am using HashSet<String>
to store values but some of String has the same hash code. How HashSet handles collision.
List<ClassA> getValuesFromA(){
}
List<ClassA> getValuesFromB(){
}
Set <String> a = new HashSet<String>(getValuesFromA()); // data overwritten due to hash code collision
Set <String> b = new HashSet<String>(getValuesFromB()); // data overwritten due to hash code collision
a.removeAll(b);
a.stream().forEach(t -> t.setSomeValue(X));
b.addAll(a);
I am using HashSet to find a minus b in O(1) for each element and then b + (a - b). But while storing data in HashSet some of the data are overwritten. Has anyone any idea to perform this operation without changing the hash method or data structure?