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 are used to represent unicodde,ASCII,UTF-16 and UTF-8 characters?
What is operator?
What are command line arguments?
How to create an instance of a class if the class has private constructor?
what is an anonymous class?
how jvm allocates memory for stack?
Write program to print Hello World and print each character address in that string and print how many times each character is in that string? Ex: H: 0 & 1 e:1 & 1 l :2,3,8 & 3 o:4,6 & 2 w:5 & 1 r: 7 & 1 d 9 & 1
What is non static block in java
How the threads are synchronized?
Explain, why the constructor is required in implemented class?
when we have to use final class in java?
relation between list and linked list