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 |
What does localhost mean?
I want to know the host name and provider name for tcs web mail
What is meant by interface?
Why do we use public static with the main function in Java?
13 Answers College School Exams Tests, Infosys,
What are decalarations?
Marker interface means , interface which has no methods.Then what is the necessity of its usage.I read "it tells the compiler that it should be treated differently ". "It is used to store state of an object". But still am not clear.Please explain clearly.
What is the numeric promotion?
Why is singleton instance static?
Can we override the static methods?
What is thread life cycle?
Explain different types of thread priorities ?
what is Dictionary? and what purpose it is used for?