Sortedset Mappings


Sortedset Mappings:

The collection of elements in a TreeSet is stored in ascending order by default, but we'll build a Comparator interface to sort the collection in descending order.

A SortedSet is a Java collection with no duplicate elements and keeps its contents in sorted order. Sets include at most one null element and no pair of items b1 and b2 such that b1.equals(b2). As a result, things that are added to a set must implement both the equals() and hashCode() methods for Java to detect if two elements/objects are identical.

A Set is started using Java.util.HashSet and mapped with a set> element in the mapping table. When we need to preserve just unique components in our collection, we may utilise the Set collection in our class.

We may use the SortedSet interface with the TreeSet implementation if we want the sort to be sorted. To be included in TreeSet, the File class must implement the Comparable interface.

  • The sort property in a set> tag may be used to indicate the Comparator class that will be used to sort the set after the files are fetched.
  • We can use "natural" instead of supplying a comparator, in which case the compareTo method will be utilised for sorting.