My code sorts a tree map but it do not print duplicate values it also show one of these duplicate values. Can I change it or no? if no, what can I do instead?
TreeMap<Double,String> hm=new TreeMap<Double,String>(Collections.reverseOrder());
hm.put(0.1,"sara");
hm.put(0.13,"nahla");
hm.put(0.13,"saeed");
hm.put(0.2,"omar");
hm.put(0.5,"olaa");
hm.put(0.5,"noha");
Set set = hm.entrySet();
Iterator i2 = set.iterator();
while(i2.hasNext()) {
Map.Entry me = (Map.Entry)i2.next();
System.out.print(me.getKey() + ": ");
System.out.println(me.getValue());
}
the output is:
0.5: noha
0.2: omar
0.13: saeed
0.1: sara
and I want to be like this:
0.5: noha
0.5: olaa
0.2: omar
0.13: saeed
0.13: nahla
0.1: sara