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

How many bits are used to represent unicodde,ASCII,UTF-16 and UTF-8 characters?

2 Answers  


What is operator?

3 Answers  


What are command line arguments?

3 Answers  


How to create an instance of a class if the class has private constructor?

3 Answers  


what is an anonymous class?

6 Answers   TCS,






how jvm allocates memory for stack?

1 Answers   HP, Ramco,


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,


What is non static block in java

10 Answers   Emphasis, Ness Technologies,


How the threads are synchronized?

2 Answers   CTS, BMC,


Explain, why the constructor is required in implemented class?

4 Answers  


when we have to use final class in java?

2 Answers  


relation between list and linked list

1 Answers   Infosys,






Categories