Tuesday, 19 April 2011

Can a null element added to a Treeset or HashSet?

A null element can be added only if the set contains one element because when a second element is added then as per set defination a check is made to check duplicate value and comparison with null element will throw NullPointerException.
HashSet is based on hashMap and can contain null element.

No comments:

Post a Comment