How to Store unique objects to avoid the duplicates in java Set?
问题 How to Store unique objects to avoid the duplicates in java Set? For example Consider Employee object which (Employee Id, name, salary....) list of employee of objects need to add in the Set. We need to restrict the Set for the duplicate elements which need to identify by the "Employee Id. What are the best way's to do? 回答1: If you are using an implementation of a java.util.Set , it should not allow duplicates as long as your equals and hashCode methods are implemented properly. Not sure why