Map的内容按字母顺序排序
2021-05-08 13:31
标签:rip import nal cti ring maps package char collect package coreJava.com.shindo.corejava.map; import java.util.ArrayList; public class MapSort { // 重写集合的排序方法:按字母顺序 return infos; public static void main(final String[] args) { final List for (final Map.Entry } } Map的内容按字母顺序排序 标签:rip import nal cti ring maps package char collect 原文地址:https://www.cnblogs.com/qq1141100952com/p/13177699.html
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
*
* @Title: sortMap
* @Description: 对集合内的数据按key的字母顺序做排序
*/
public List
final List
Collections.sort(infos, new Comparator
@Override
public int compare(final Entry
return (o1.getKey().toString().compareTo(o2.getKey()));
}
});
}
final Map
map.put("charSet", "utf-8");
map.put("merId", "5412");
map.put("acqId", "321");
System.out.println(m.getKey() + ":" + m.getValue());
}
上一篇:Python基础-字符串