Time:09-21
CodePudding user response:
Treeset collection cannot be stored in the collection of HashSet type? If not, why not?
don't understand your question Deposit is treeset hashset elements, or deposit treeset hashset object? 1 if it is to point to the former, with the LS said treeset elements cannot be null, treeset elements to implement the Comparable interface, because the internal invokes the Comparable interface method to sort (so null element method call interface will be a null pointer exception, if not null elements not achieve Comparable interface can also because can't find the interface method and error) 2 if it is to point to the latter, because the hashset itself does not implement the Comparable interface, so you can't store
Quote: refer to the second floor qybao response: don't understand your question Deposit is treeset hashset elements, or deposit treeset hashset object? 1 if it is to point to the former, with the LS said treeset elements cannot be null, treeset elements to implement the Comparable interface, because the internal invokes the Comparable interface method to sort (so null element method call interface will be a null pointer exception, if not null elements not achieve Comparable interface can also because can't find the interface method and error) 2 if it is to point to the latter, because the hashset itself does not implement the Comparable interface, so you can't store Is I created three collections: A hashset type set of type String is put inside a A collection of treeset type b type int is put inside the element A collection of the arraylist type c inside a custom object of type Then I created a collection of treeset type D, placed inside the above three collections, the runtime adds the collection statement in a to D make a mistake, is this why?
Page link:https//www.codepudding.com/Backend/19248.html