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

Can we use return in constructor?

0 Answers  


What are the notations in Java?

1 Answers   Cap Gemini,


Why singleton is not thread safe?

0 Answers  


Why cant we define System.out.println() inside a class directly?

5 Answers  


What is a instance variable in java?

0 Answers  






Is string passed by reference in java?

0 Answers  


What is serialversionuid?

0 Answers  


What is the return type of read()?

3 Answers  


Which is easier netbeans or eclipse?

0 Answers  


What is parse method?

0 Answers  


What are the restrictions imposed on method overriding?

0 Answers  


What is meant by overloading?

0 Answers  


Categories