1、根据key排序
Map<String,String> result = new HashMap<>();
Map<String,String> map = new HashMap<>();
map.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEachOrdered(x->result.put(x.getKey(),x.getValue()));
2、根据value排序
Map<String, Integer> valueResult = new HashMap<>();
Map<String, Integer> map = new HashMap<>();
map.entrySet().stream()
.sorted(Map.Entry
.comparingByValue())
.forEachOrdered(b->valueResult.put(b.getKey(), b.getValue()));