import java.util.HashMap; import java.util.Map; import java.util.TreeMap; public class Demo { public static void main(String[] args) { HashMap<String, String>map = new HashMap<String, String>(); map.put("1", "A"); map.put("6", "B"); map.put("3", "C"); map.put("7", "D"); map.put("5", "E"); map.put("2", "F"); map.put("4", "G"); map.put("8", "H"); Map<String, String>tMap = new TreeMap<String, String>(map); System.out.println("Sorted Map values: "+tMap); } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more