Solution: Sorted Hashtable

- -

For a problem I face in my code, I want a key-value pair with quick lookup and a sorted set of keys. Sounds like a job for TreeMap, right?

The wrinkle is that I’d like an option for ascending and descending order, not just the natural order of my keys.

Enter a forum post on Comparators in descending order. I can feed this Comparator to my TreeMap, then I get the sorting I’d like.

Just thought I’d share!