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
If a class is declared without any access modifiers, where can the class be accessed?
how to know the total memory occupied by the objects in the ArrayList(Array list may contain duplicate objects)
Can a string be null?
what state does a thread enter when it terminates its processing? : Java thread
What is the declaration statement?
What is the difference between and ?
What are classloaders?
Convert a BST into a DLL and DLL to BST in place.
What is space character in java?
How to check if linked list contains loop in java?
Explain method overloading?
What is string pool in java?
What is the difference between length and length() method in java?
What are the three parts of a lambda expression? What is the type of lambda expression?
Is it possible to use string in the switch case?