[Solved] Calendar order in java [closed]


use TreeSet, by implementing Comparator interface and providing reverse sorting logic and finally add all elements of HashSet to TreeSet using addAll() method of Collection interface.

// using Comparator constructor argument of TreeSet
TreeSet < String > ts = new TreeSet < String > (new Comparator < String > () {

 @Override
 public int compare(String o1, String o2) {
  // reverse sorting logic
  return o2.compareTo(o1);
 }
});

// add HashSet elements to TreeSet
ts.addAll(grandChildren);

System.out.println("\n\n\nAfter Sorting : Descending order\n");

// Iterating using Iterator
Iterator < String > ascSorting = ts.iterator();
while (ascSorting.hasNext()) {
 System.out.println(ascSorting.next());
}

4

solved Calendar order in java [closed]