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 nextline method in java?
How do you sort a list in java?
What is the major advantage of external iteration over internal iteration?
What is the simpletimezone class in java programming?
Hi all, I am dng a mini project on FileSplitter application which splits the GBs of logfile into Smaller chunks(mbs) depending on the split size." How to handle GBs file? I am getting OutOfMemoryException, when I input such GB sized file. Thx
What is contractor means and methods?
How do you identify if jvm is 32-bit or 64-bit from java program?
How to connect to a remote database using Applet?
Can a method be overloaded based on different return type but same argument type?
What is the difference between a switch statement and an if statement?
Can we declare a class as abstract without having any abstract method?
How do you convert bytes to character in java?
What is difference in between java class and bean?
What is the current version of java?
Can java program run without jre?