常用的代码块.md 645 B


title: Java常用代码块 date: 2016-11-08 tags: Java comments: false cover: https://static.jqwei.com/blog/img/IMG_3461.PNG

categories: 运维工具

java常用代码块

map 根据Key排序

    /**
     * map 按 key 升序排序
     *
     * @param map
     * @return
     */
    private static Map<String, Object> sortByKey(Map<String, Object> map) {
        Map<String, Object> result = new LinkedHashMap<>(map.size());
        map.entrySet().stream()
                .sorted(Map.Entry.comparingByKey())
                .forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
        return result;
    }