Iterating Through A List And Removing Duplicate Items in apex
<p>I want to remove the duplicate entries based on the Name field from the list.
Below is my Code..</p>

<pre><code> public class EPM_Contact_Component_Class {
     public List&lt;Hospital_Contacts__c&gt; conList { get; set; }
     public List&lt;Hospital_Contacts__c&gt; result { get; set; }
     public JCT_Hospital_Model__c jctObj { get; set; }
     public Set&lt;Hospital_Contacts__c&gt; myset { get; set; }

 public EPM_Contact_Component_Class(ApexPages.StandardController controller) { }

 public List&lt;Hospital_Contacts__c&gt; getContacts() {
     conList = new List&lt;Hospital_Contacts__c&gt;();
     jctObj = new JCT_Hospital_Model__c();
     jctObj = [Select EPM_Model__r.Name,Hospital__r.Name from JCT_Hospital_Model__c where Id=:ApexPages.currentPage().getParameters().get('Id')];
     system.debug(jctObj.EPM_Model__r.Name);
     conList = [select Contacts__r.Name,Contacts__r.Email,Contacts__r.Phone from Hospital_Contacts__c where EPM_Model__r.Name =: jctObj.EPM_Model__r.Name and Hospital__r.Name=:jctObj.Hospital__r.Name  ORDER BY Contacts__r.Name DESC ];

     myset = new Set&lt;Hospital_Contacts__c&gt;();
     result = new List&lt;Hospital_Contacts__c&gt;();

      for(integer i=0;i&lt;conList.size();i++) {
             Hospital_Contacts__c hospi = conList.get(i);
         for(integer j=(i+1);j&lt;conList.size();j++) {

             Hospital_Contacts__c hospj = conList.get(j); 
             if(hospi.Contacts__r.Name == hospj.Contacts__r.Name) {
                 conList.remove(j); 
                 system.debug('REMOVED::'+j);  
             }
         }
     }
     return conList;
 }

}
</code></pre>

<p>It works fine with 2 duplicates..When there are more than 2 duplicates, it returns the Name 2 times. 
Anybody can help me please?</p>