14 April, 2013

set: does it allow duplications?



set: does it allow duplications? 
How to insert e4 and e5 which are object of Employee class which has same attributes in set?
Set doesnot allow duplicate ele. We can insert e4 and e5 with same attributes if in the Employee class we have not overridden the equals and hashCode method
       Set.add(ele) return boolean value
       If duplicate ele is inserted then no compile time exception, no runtime exception will be thrown.
       boolean b1 = set.add("a"); // true
       boolean b2 = set.add("a"); // false

No comments:

Post a Comment