Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to iterate SortedSet / SortedMap in Java backwards

Tags:

I need to iterate through SortedMap's entry set (which is a SortedSet) backwards. The code I'm writing is extremely performance-sensitive, as it's going to be called from many places thousands times per second, maybe more. Any advice on doing it the fastest way?

like image 930
Alexander Temerev Avatar asked Mar 16 '09 22:03

Alexander Temerev


People also ask

How do you reverse a Sortedset in Java?

To sort TreeSet in descending order, use the descendingSet() method in Java. The descendingSet() method is used to return a reverse order view of the elements contained in this set.


1 Answers

In Java 1.6 you can use NavigableSet.

like image 68
starblue Avatar answered Nov 04 '22 20:11

starblue