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 / 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 |
How many bits is size_t?
Differentiate between stringbuffer and string?
What is the difference between interpreter and compiling ?
Is java pure object oriented or not? if yes, give the valid reason.
13 Answers Emphasis, NIIT, Syntel, Wipro,
Why wait and notify methods are declared in object class?
Explain different ways of creating a thread. Which one would you prefer and why?
What is a list in java?
What flag up means?
Is list ordered in java?
Explain about version control?
Does java list allow null?
describe synchronization in respect to multithreading? : Java thread