nisu pathak wrote:
set interface is not threadsafe & if i am implementing Hashset than it allows me to have null value as a property.but when it come to TreeSet implementation,it does not allow me to specify null as a property,when i run the code it will give me NullPointerException.does anyone know the reason?
The common version of TreeSet (that does natural ordering) takes Comparable elements. And although null IS-A Comparable, it can't be used as one -- it will generate an NPE when trying to call the compareTo() method.
If you want to place null values into the TreeSet, you will need to provide a Comparator to order to sort them.
Henry