JAVA8, if you want to sort the words according to the value of the map, it's more cumbersome to see how to HashMap, sort by value
Now it's much easier to use lambda expressions.
<span style= "FONT-SIZE:14PX;" >Map<String,Integer> map=new hashmap<> (), Map.put ("Derek", "Map.put" ("Dad", "Wuyi"), Map.put ("Mom", 46); List<map.entry<string, integer>> list=new arraylist<> (); List.addall (Map.entrySet ());// Collections.sort (List,new comparator<map.entry<string, integer>> () {//public int compare (Map.Entry< String, integer> m1,map.entry<string, integer> m2) {//return m1.getvalue ()-m2.getvalue ();//}//}); Collections.sort (list, (M1, M2)->m1.getvalue ()-m2.getvalue ()); List.foreach (System.out.println (M.getkey ( ));</span>
The commented out part is the previous way, now only need a short line of code can be done, traversal is also a lot of convenience.
The functional programming that lambda expressions bring to Java is really sharp, and with the enhanced type inference in Java8, the code becomes simple and understandable ~
Manipulating HashMap using lambda expressions