Sample code to retrieve objects from HashMap in sorted
ascending order?

Answers were Sorted based on User's Feedback



Sample code to retrieve objects from HashMap in sorted ascending order?..

Answer / murli

Map hm = new HashMap();
//add values to hashmap
Map tm = new TreeMap(hm);
//Iterate keySet in tm

Is This Answer Correct ?    9 Yes 2 No

Sample code to retrieve objects from HashMap in sorted ascending order?..

Answer / amit badgujar

Yes it is correct

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

Are arrays immutable in java?

0 Answers  


There are 100 keys and values in HashMap.how to get the keys and values?

1 Answers   IBS,


4.1 Supply contracts (in the form of comments specifying pre- and post conditions) for the enqueue() method of the LinkedQueue class given in the Appendix. (2) 4.2 Let Thing be a class which is capable of cloning objects, and consider the code fragment: Thing thing1 = new Thing(); //(1) Thing thing2 = thing1; //(2) Thing thing3 = (Thing) thing1.clone(); //(3) Explain how the objects thing2 and thing3 differ from each other after execution of the statements. (

0 Answers  


What value is a variable of the string type automatically initialized?

0 Answers  


What do you understand by an io stream?

0 Answers  


What is difference between length and length() method in java ?

0 Answers  


What is class and its types?

0 Answers  


Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.

0 Answers  


How do you initialize an arraylist in java?

0 Answers  


What is mean by collections in java?

0 Answers  


Can we pass a primitive type by reference in java? How

0 Answers  


What is the return type of the main method?

0 Answers  


Categories