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

Explain, why the constructor is required in implemented class?

4 Answers  

What is hypertext?

1 Answers  

My application URL : http://localhost:8080/Application/Login.jsp. When a user enter this url in IE then, how it get Login.JSP Page exactly? what are the processes will happen from when we submit the URL to get Login.jsp?

3 Answers   IBM, TCS,

What is serialVersionUID and what is its need?

1 Answers   KPIT,

what r advatages of websphere? & how to deploy?

0 Answers   Saksoft,

can you use the two main method in same class?how?

4 Answers   DELL, SparkTG, Geosoft,

what is filters and its use?

2 Answers   Virtusa,

Features of JAVA ? In which version of java synchronizedXXX() methods are included in Collections class.

1 Answers   NIIT,

What is the life cycle of Thread ?

12 Answers   HCL, Varnar Softech,

when to use abstract class and when to use interface?

16 Answers   iGate, IonIdea, Exterro,

What is Co-Variant return type in method overriding?

1 Answers   RBS,

I have 100 records in a table with two rows. I need to display 10 records per page like Google Search. I need only the Logic(Pagination) in Pure Java. No JSP and all..Thanks in Advance...

2 Answers   Cybernet,