title: How to customize java hashset for checking duplication on the basis of set object instance variable value
body: <p>By default set can not have a duplicate records, but suppose I have class</p>
  
  <pre><code>class Employee {
     Integer emp_id;
      String name;
     // other fields and their getter 
    Employee(String name) {
         emp_id++;
     this.name=name;
  }
  }
  </code></pre>
  
  <p>Now I declare a set in my other class</p>
  
  <pre><code>       set&lt;Employee&gt; empSet = new HashSet&lt;Employee&gt;();
        Employee e1 = new Employee ("abc");
        Employee e2 = new Employee ("abc");
  </code></pre>
  
  <p>so while insert it to the set</p>
  
  <pre><code>      empSet.add(e1);
        empSet.add(e2);
  </code></pre>
  
  <p>Then first e1 add to set but second e2 returns false.</p>
  
  <p>Now what I want that there is no duplication of their name. So I want to check while insert into set.</p>