SyntaxFix
Write A Post
Hire A Developer
Questions
A TreeMap is always sorted by the keys, anything else is impossible. A Comparator merely allows you to control how the keys are sorted.
TreeMap
Comparator
If you want the sorted values, you have to extract them into a List and sort that.
List