Przeglądaj źródła

添加 '_posts/常用的代码块.md'

aaronwei 5 lat temu
rodzic
commit
b444cb9651
1 zmienionych plików z 28 dodań i 0 usunięć
  1. 28 0
      _posts/常用的代码块.md

+ 28 - 0
_posts/常用的代码块.md

@@ -0,0 +1,28 @@
+----
+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<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;
+    }
+```