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

what is platform native code

2 Answers   i3 Solutions,

What is the immediate superclass of Menu?

3 Answers  

What is difference between “==” and equals()?

1 Answers   IBM,

Write program to print Hello World and print each character address in that string and print how many times each character is in that string? Ex: H: 0 & 1 e:1 & 1 l :2,3,8 & 3 o:4,6 & 2 w:5 & 1 r: 7 & 1 d 9 & 1

7 Answers   IBM, Huawei,

In Java why we write public static void main(String args[]) why not main()?

46 Answers   TCS, Microsoft, Wipro, Aptech, Infosys, GE Healthcare, Practical Viva Questions, New Horizon,

Hi i am creating desktop application in that i want calling to mobile number. i have java telephone api (JTAPI) but i dont understand how it configure & use plese help me

0 Answers  

java Api provided try catch finally ,try catch(its ok) but why try finally and exception occured at try then how the flow is?

1 Answers   Naaptol,

what is language and it responsibilities

1 Answers  

how we can use debug in myeclipse 6.0 in order solve the problems that exist in our program when there are 900 to 1000 pages in a web application

0 Answers   SAP Labs,

How to override a equals() method and what is the use?

1 Answers  

Can multiple catch statements be used in exceptions ?

6 Answers   Wipro,

What is meant by final class, methods and variables?

3 Answers