Java HashSet contains duplicates if contained element is modified

The situation you describe is invalid. See the Javadoc: “The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set.”

Leave a Comment