HashMap倒序

//map排序
Map<String, String> map = new HashMap<String, String>();
map.put("1","value1");
map.put("2","value2");


		TreeMap tmp = this.compositorMap(map);
		Set set = tmp.keySet();

		for (Object key : set)
		{
			String str = (String)tmp.get(key);
                        System.out.println("==="+str);
                }



/**
	 * hashMap排序
	 * @param map
	 * @return
	 * @throws Exception
	 */
	private TreeMap compositorMap(Map<String, String> map) throws Exception
	{
		TreeMap tm = new TreeMap(new Comparator()
		{
			public int compare(Object o1, Object o2)
			{
				return o1.hashCode() - o2.hashCode();
			}
		});
		
		tm.putAll(map);
		
		return tm;
	}



你可能感兴趣的:(HashMap)