I have keys values, now I would like sort values only by adding it to the tree-set. Because tree-set performs the ascending order sorting.
There exist a method that converting called converting map to list. But it is a hectic method, can any one comment about this?
package practice;
import java.io.ObjectInputStream.GetField;
import java.util.*;
import java.util.Map.Entry;
public class example1{
public static void main(String[] args) {
Map<Integer,String> map = new HashMap<Integer,String>();
map.put(1, "h");
map.put(2, "l");
map.put(3, "a");
System.out.println(map);
System.out.println("unsort");
for(Map.Entry m:map.entrySet()) {
System.out.println(m.getKey()+" - "+m.getValue());
}
System.out.println("sorting by values");
}
}