Search code examples
javacollections

The best way to iterate SortedSet / SortedMap in Java backwards


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?


Solution

  • In Java 1.6 you can use NavigableSet.