TreeMap

Map的key的类型 可以是int或者String类型,类型不同排序的结果也不同。

		String[] arr = {"12,bob","3,sky","6,cool","1,good","22,go"};
		
		TreeMap<String, String> tmap = new TreeMap<String, String>();
		for(int i=0; i<arr.length; i++){
			tmap.put(String.valueOf(arr[i].split(",")[0]), arr[i].split(",")[1]);
		}
		

		
		Iterator<Entry<String, String>> ite = tmap.entrySet().iterator();
		while(ite.hasNext()){
			Map.Entry<String, String> entry = ite.next();
			System.out.println(entry.getKey() + " - " + entry.getValue());
		}
	}
	
	

  

原文地址:https://www.cnblogs.com/ydxblog/p/5650787.html