By convention, all
Collection implementations provide a standard constructor that takes a Collection, and SortedSet implementations are no exception. This constructor creates a SortedSet object that orders its elements according to their natural order. Additionally, by convention, SortedSet implementations provide two other standard constructors: - One that takes a
Comparatorand returns a new (empty)SortedSetsorted according to the specifiedComparator. - One that takes a
SortedSetand returns a newSortedSetcontaining the same elements as the givenSortedSet, and sorted according to the sameComparator(or using the elements' natural ordering, if the specifiedSortedSetdid too). Note that the compile-time type of the argument determines whether this constructor is invoked in preference to the ordinarySetconstructor, and not the runtime type!
SortedSet with an explicit Comparator. The second is similar in spirit to the standard Collection constructor: it creates a copy of a SortedSet with the same ordering, but with a programmer-specified implementation type.
No comments:
Post a Comment