title: How to add object with unique field to Set
body: <p>How can I fill a Set by objects with unique field ? </p>
  
  <p>For example I have a class <code>Person</code> which has an unique field called <code>name</code> thus if I add to Set an object with duplicate name it should not be added.</p>
  
  <pre><code>public class Test {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          Set&lt;Person&gt; objList = new HashSet&lt;Person&gt;();
          objList.add(new Person("John", "New York", "Accountant"));
          objList.add(new Person("Bill", "London", "Manager"));
          objList.add(new Person("John", "New York", "Driver"));// this object should not be added
  
          for(Person o : objList){
              System.out.println(o.name);//here should printed only John and Bill
          }
      }
  }
  
  class Person {
      String name;//must be unique
      String city;
      String position;
  
      public Person(String c_name, String c_city, String c_position){
          this.name = c_name;
          this.city = c_city;
          this.position = c_position;
      }
  }
  </code></pre>