You don't use the TreeSet to look up entries, so it would be better to use an ArrayList and sort it explicitly. Also, it's not at all clear from the code that the entries are sorted in reverse order.