NavigableSet is an interface, so i would say a, is a questionable answer from one perspective. However, from the perspective of answer b, NavigableSet interface is mainly implemented by TreeSets (There is also NavigableMap for TreeMaps). Looking at NavigableSet its methods work on ranges of data such as lower() and higher() so it would make no sense to call these on null values, after all what would higher(null) actually produce?
This is just a guess
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
As far as I know there is no rule that says that you can't have the null element in a set (So Answer B is wrong.) The only problem is that if the set is ordered using natural ordering, having the null value will throw a NullPointerException at runtime. But if you use a Comparator instance that provides for the null element, then you won't have any problems. Here is an example:
All code in my posts, unless a source is explicitly mentioned, is my own.
TreeSet implements NavigableSet, so if there were any restriction to add null elements to a NavigableSet, I think that would also be present in TreeSet. I couldn't find mention of any such restriction in the NavigableSet API documentation either. Have you read anywhere about this restriction?
All code in my posts, unless a source is explicitly mentioned, is my own.
The main thing is that all elements must be mutually comparable. If you use natural ordering, null will give you problems. But if you use an acceptable Comparator, then it won't be an issue.
All code in my posts, unless a source is explicitly mentioned, is my own.
Well I suppose if you try and add more than one null, your going to get issues, but that doesn't stop you from adding at least one! Maybe one of the Sheriff's may be able to shed more light on the issue?
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Trust God, but always tether your camel... to this tiny ad.