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.



I have a sorting issue with a Hashmap. My constraint is that I MUST use the Hashmap and work with..

Answer / 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

More Core Java Interview Questions

Differentiate between stringbuffer and stringbuilder in java.

0 Answers  


How can you make sure that your singleton class will always return single instance in multi-threaded environment?

0 Answers  


What is serialversionuid?

0 Answers  


Explain Global variables in Packages?

4 Answers  


What are constants and how to create constants in java?

0 Answers  






What are the files generated after using IDL to java compiler?

0 Answers  


Does the order of public and static declaration matter in main method?

0 Answers  


What variables are stored in stack?

0 Answers  


Which is better singleton or static class?

0 Answers  


What is protected and friendly?

1 Answers  


Explain the reason behind ending a program with a system.exit(0)?

0 Answers  


Explain about core java?

0 Answers  


Categories