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 Posted / 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 View All Answers
What are predefined functions?
Can an interface be defined inside a class?
Are floats faster than doubles?
How can you traverse a linked list in java?
What is ++ a in java?
Explain an intermediate language?
What is regex java?
What is a parameter used for?
How many bytes is double?
How can I become a good programmer?
How do you add an element to an arraylist in java?
What is Java Shutdown Hook?
Can we convert list to set in java?
How do you define a variable?
What is meant by method overriding?