If you are thinking about performance, then large results are better sorted at the end of the database, especially when the columns you are sorting are indexed.
For smaller performance differences, the data sets may not be significant, but I think the SQL Order By clause will be simpler in most cases.
By the way, you still have to use LinkedHashMap instead of a simple HashMap, if you must save the already sorted data on the map before using it. Since LinkedHashMap will store data in input order, while HashMap will not.
If you want the data to be automatically sorted as it is placed on the map, you will need TreeMap or another sorted map implementation.
source share