Home java Sort TreeSet in reverse order

Sort TreeSet in reverse order




Tell me how to sort TreeSet in reverse order.
If simply set can be done like this:

list & lt; integer & gt; List = New ArrayList ();
  List.Add (5);
  list.add (59);
  List.Add (21);
  Collections.sort (List, collections.reverseorder ());
  Set ResultSet = New LinkedHashset (List);

And how to make the most for TreeSet?

Answer 1, Authority 100%

You can use descendingset

TreeSet & lt; integer & gt; timeadd = new treeset & lt; integer & gt; ();
TreeSet & LT; Integer & GT; TreeReverse = New TreeSet & LT; Integer & GT; ();
// add data
timeadd.add (1);
timeadd.add (13);
timeadd.add (17);
timeadd.add (2);
// Deploy
TreeReverse = (TreeSet) TreeADD.DescendingSet ();

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions