Java HashMap sort on key value vis TreeMap
import java.util.HashMap; import java.util.Map; import java.util.TreeMap; public class Main { public static void main(String[] args) { HashMap<String, String> hm = new HashMap<String, String>(); hm.put("4", "four"); hm.put("3", "Java"); hm.put("1", "CSS"); hm.put("5", "CSS"); hm.put("6", "HTML"); hm.put("0", "CSS"); hm.put("2", "HTML"); System.out.println(hm);/* w w w .ja v a 2 s .c om*/ Map<String, String> treeMap = new TreeMap<String, String>(hm); System.out.println(treeMap); } }