What would be better programing practice?
Is it better to use order by clause in sql or put the results in treemap vs hashmap in java for things like drop down?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are thinking about performance, then big resultsets are better sorted at the database end, especially when the columns you are sorting on are indexed.
For smaller data-sets performance difference might not be significant, but I think SQL’s Order By clause will be the simpler approach in most cases.
By the way you will still have to use LinkedHashMap instead of plain HashMap if you must store the already sorted data in a map before using it. Because LinkedHashMap will keep the data in insertion order while HashMap won’t.
If you want the data to be automatically sorted as it is put into the Map then you will need TreeMap or another sorted map implementation.