---- title: Java常用代码块 date: 2016-11-08 tags: Java comments: false cover: https://static.jqwei.com/blog/img/IMG_3461.PNG categories: 运维工具 --- ## java常用代码块 ### map 根据Key排序 ``` java /** * map 按 key 升序排序 * * @param map * @return */ private static Map sortByKey(Map map) { Map result = new LinkedHashMap<>(map.size()); map.entrySet().stream() .sorted(Map.Entry.comparingByKey()) .forEachOrdered(e -> result.put(e.getKey(), e.getValue())); return result; } ```