title: Java - Why does Map.put() overwrite while Set.add() does not?
body: <p>I am wondering what the rationale is behind having Java's <code>Map.put(key, value)</code> method overwrite equivalently key'd values that are already in the collection, while <code>Set.add(value)</code> does not overwrite a pre-existing equivalent value that is already in the collection?</p>
  
  <h2>Edit:</h2>
  
  <p>It looks like majority viewpoint is that objects in a set that evaluate to equality should be equal in every respect, thus it shouldn't matter if Set.add(Object) overwrites equivalently valued objects or not.  If two objects evaluate to equality, but do in fact hold different data, then a Map-type collection is a more appropriate container.  </p>
  
  <p>I somewhat disagree with this veiwpoint.<br>
  Example:  A set holding a group of "Person" objects.  In order to update some information about that person, you might want to pass the set a new, updated, person object to overwrite the old, outdated person object.  In this case, a Person would hold a primary key that identifies that individual and the set would identify and compare people based only on their primary keys.  This primary key is part of the person's identity as opposed to an external reference such as a Map would imply.</p>