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

Why are the objects immutable in java?

0 Answers  


Can memory leak in java?

0 Answers  


What are the types of literals?

0 Answers  


What is meant by vector class, dictionary class, hash table class, and property class?

0 Answers  


how can we import the user defined package without classpath?

1 Answers   CSC, Infosys,


Why are the destructors for base class and derived class called in reverse order when the program exits

0 Answers   HCL,


What is an association?

0 Answers  


Explain about fail safe iterators in java?

0 Answers  


Why we should declare the variables as static and final in interfaces?

1 Answers  


What is unicode with example?

0 Answers  


what is mean by ooad? where we are using? can you tell me any real time example?

1 Answers   Eka Software,


How many objects are created for a singleton class

7 Answers   Ness Technologies,


Categories