I\'ve read this question: Changing the elements in a set changes the \'equals\' semantics
However, I don\'t know how to solve the problem that I can\'t change an ite
You are facing the problem because the keys in your hashset are not immutable. If you don't have immutable keys, you will lose the reference of the original key object once modified. And will never be able to get handle of that, which is sometimes referred as memory leaks in collection. So if you use immutable keys, you wouldn't run into this situation.