JDK8 之 Map 排序
public class MapUtil {
/**
* JDK8
* 按照Key排序
*
* @param map map数据
* @param asc 是否升序
* @param <K> Key
* @param <V> Value
* @return Map<K, V>
*/
private static <K extends Comparable<? super K>, V> Map<K, V> sortByKey(Map<K, V> map, boolean asc) {
Map<K, V> result = new LinkedHashMap<>();
Stream<Map.Entry<K, V>> stream = map.entrySet().stream();
if (asc) {
stream.sorted(Map.Entry.comparingByKey()).forEachOrdered(e -> result.put(e.getKey(), e.getValue