java map的默認排序問題


    1. import java.util.HashMap;  
    2. import java.util.LinkedHashMap;  
    3. import java.util.Map;  
    4. import java.util.TreeMap;  
    5.   
    6. public class Test {  
    7. public static void main(String[] args) {  
    8.     Map tree = new TreeMap();  
    9.     Map linked = new LinkedHashMap();  
    10.     Map hash = new HashMap();  
    11.     System.out.println("tree :"+buildMap(tree));  
    12.     System.out.println("link :"+buildMap(linked));  
    13.     System.out.println("hash :"+buildMap(hash));  
    14. }  
    15. private static Map buildMap(Map map){  
    16.     map.put("0""a");  
    17.     map.put("e""b");  
    18.     map.put("4""s");  
    19.     map.put("3""c");  
    20.     return map;  
    21. }  

    22. 輸出結果:
      1. tree :{0=a, 3=c, 4=s, e=b}  
      2. link :{0=a, e=b, 4=s, 3=c}  
      3. hash :{3=c, 0=a, 4=s, e=b} 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM