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
Comparator
and returns a new (empty)SortedSet
sorted according to the specifiedComparator
. - One that takes a
SortedSet
and returns a newSortedSet
containing the same elements as the givenSortedSet
, and sorted according to the sameComparator
(or using the elements' natural ordering, if the specifiedSortedSet
did too). Note that the compile-time type of the argument determines whether this constructor is invoked in preference to the ordinarySet
constructor, 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