//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倒序
最新推荐文章于 2023-02-28 14:02:11 发布