Java HashMap转TreeMap

来源:互联网 发布:网络手游可以破解吗 编辑:程序博客网 时间:2024/06/06 20:53

Map<String, String> testMap = new HashMap<String, String>();testMap.put("1", "3");testMap.put("3", "4");testMap.put("2", "1");testMap.put("4", "2");for (String key : testMap.keySet()) {    System.out.println(key + "=>" + testMap.get(key));}System.out.println("========================");Map<String, String> testMap2 = new TreeMap<String, String>(testMap);for (String key : testMap2.keySet()) {    System.out.println(key + "=>" + testMap2.get(key));}

3=>42=>11=>34=>2========================1=>32=>13=>44=>2