码迷,mamicode.com
首页 > 其他好文 > 详细

TreeMap

时间:2016-07-07 19:06:15      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

 

 

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());
		}
	}
	
	

  

TreeMap

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!