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


Please Help Members By Posting Answers For Below Questions

What is singleton service?

496


How do you replace a string in java?

535


Can a abstract class be defined without any abstract methods?

546


What is thread count in java?

536


What is nan inf?

493






What’s the difference between applets and standalone program?

522


Explain the significance of class loaders in bootstrap?

491


Can a list be null in java?

533


What is data and its types?

566


What is difference between variable declaration and definition?

505


What is a variable simple definition?

570


What is independent and dependent variables in research?

460


What is substring 1 in java?

579


What is broken and continue statement?

524


What is private static in java?

569