java中不同map的默认排序

转载博客:https://www.cnblogs.com/magic-melody/p/6061093.html

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
	    Map tree = new TreeMap();  
	    Map linked = new LinkedHashMap();  
	    Map hash = new HashMap();  
	    System.out.println("tree :"+buildMap(tree));  
	    System.out.println("link :"+buildMap(linked));  
	    System.out.println("hash :"+buildMap(hash));  
	}
	private static Map buildMap(Map map){  
	    map.put("0", "a");  
	    map.put("e", "b");  
	    map.put("4", "s");  
	    map.put("3", "c");  
	    return map;  
	} 

}


结果
tree :{0=a, 3=c, 4=s, e=b}
link :{0=a, e=b, 4=s, 3=c}
hash :{0=a, 3=c, 4=s, e=b}



 

你可能感兴趣的:(java,基础知识)