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 does Vector implement synchronization?
Do we have pointers in java?
does core java and j2se both are same?
What is the difference between && and & in java?
StringBuilder s = new StringBuilder("Hello Mom");s.append(",I mean,Mother"); Response.Write(s.ToString()); String s = "Hello Mom"; s+ = ",I mean Mom"; Response.Write(s); Which is faster ? which uses the most memory?
v-model life cycle
Is java platform independent?
what is webservices
5 Answers Consultancy, Mind Tree,
Can we store variables in local blocks?
What is the difference between synchronized and synchronized block?
Is null a string in java?
What is the difference between exception and error in java?