成语大全网 - 成语词典 - 如何对Map进行字典排序Java

如何对Map进行字典排序Java

//根据 Map的key进行字典排序

Map<String, String> parameterMap = new HashMap<String, String>();

List<Map.Entry<String,String>> list = new ArrayList<Map.Entry<String,String>>(parameterMap.entrySet());

Collections.sort(list,new Comparator<Map.Entry<String,String>>() {

//升序排序

public int compare(Entry<String, String> o1,

Entry<String, String> o2) {

return o1.getKey().compareTo(o2.getKey());

}

});