1

While working on application where I want to discard duplicate entries for my value object (user defined VO), I used Set data structure by overriding hashCode(), equals() method.

I tried few iteration, it works fine but thing here I want to understand how uniqueness actually maintained? Is old object get replaced with new one or simply new one get ignore?

As they are identical how can I check above?

Thanks

Sagar
  • 125
  • 1
  • 15

1 Answers1

0

According to the javadoc: [Set.add()] Adds the specified element to this set if it is not already present. If this set already contains the element, the call leaves the set unchanged and returns false. So answer your question "Is old object get replaced with new one or simply new one get ignore?" is new one get ignore

Borodin.Mik
  • 332
  • 1
  • 4
  • 11