I have a sorting issue with a Hashmap. My constraint is that
I MUST use the Hashmap and work with existing code. I do a
database query and place the results in a Hashmap. When I
iterate thru the Hashmap, it loses the original alphabetical
sorting done by the database. So, my problem is that I must
sort the results coming out of the Hashmap which is then
placed into another class.

Answer Posted / murali.25

1) Use a tree map or construct a treemap from hashmap.
2) If you have used order by in the query to DB, use LinkedHashMap
3) Have a java class with attributes corresponding to fields from the database table. Implement comparator interface.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is intern method in java?

804


Is array passed by reference in java?

796


What does it mean to be immutable?

755


What is the program development process?

746


How to sort array in descending order in java?

720


what is an objects lock and which objects have locks? : Java thread

773


What language is pass by reference?

773


Are arrays static in java?

790


How big is a 64 bit float?

764


Where is the find and replace?

747


Why volatile is used in java?

750


Does collectionutils isempty check for null?

1117


Does unicode support all languages?

772


Why do we override tostring method in java?

686


What is array sorting in java?

777