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

what is the diffrences between platform independent and portable

5 Answers   TCS,


Can I overload to string method

0 Answers   UHG,


what is different between static and non static methods ,using example

2 Answers  


Are nested try statements are possible?

2 Answers  


What is meant by Encapsulation? Can you write a class to explain encapsulation?

8 Answers   Ness Technologies,






What are possible key words, we can use to declare a class?

2 Answers   Tech Mahindra,


what is Vector class?

2 Answers  


What is Yield() method when we r using this ? tell exactly

2 Answers  


What is access modifiers?

1 Answers   Cap Gemini,


write SQL command for table employee where print first name or last name start like "A" and who is working in domain(angular js,java,dotnet)

0 Answers  


explain System.out.println()

12 Answers   CTS,


JSP is by default thread safe or not? what is the meaning of isThreadSafe="true" and isThreadSafe="false". Explain it? Thanks, Seenu

9 Answers   Huawei,






Categories