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 is the difference between static (class) method and instance method?
What are the important methods of java exception class?
What is the maximum size of byte array in java?
What is concurrent hashmap and its features?
What are the two types of exceptions in java? Which are the differences between them?
What is the method in java?
How many types of constructors are used in java?
What are the 4 types of characters?
What are methods and how are they defined?
Explain the pointers in Java?
What is Enum in Java?
Which is bigger float or double?
What is callable java?
Write code of any action class?
How can you traverse a linked list in java?