Java HashMap转TreeMap


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=>4
2=>1
1=>3
4=>2
========================
1=>3
2=>1
3=>4
4=>2


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM