I have written a temporary test code.
But it is giving the incorrect result.
Could you please tell me where I am making a mistake?
package FirstTry;
import java.util.*;
public class SortingMap
{
public static void main(String[] args)
{
Map<String, Double> unsorted = new HashMap<String, Double>();
unsorted.put("a", 100.0);
unsorted.put("b", 55.0);
unsorted.put("c", 200.0);
unsorted.put("d", 55.0);
Comparator<String> compare = new Comparator<String>()
{
public int compare(String o1, String o2)
{
return o1.compareTo(o2);
}
};
Map<String, Double> sorted = new TreeMap<String, Double>(compare);
sorted.putAll(unsorted);
System.out.println(sorted);
}
}

New Topic/Question
Reply



MultiQuote




|