Java map sorted according to the value of the map value

1      // The sales ranking query 
2      public  void queryGoodsByHotCount () {
 . 3          // will map to a set of entry keys and values encapsulated object and then converted into a set of set 
. 4          the Set <the Entry <Integer, Goods >> setGoods = mapGoods.entrySet () ;
 5          // will turn into a set of set list set 
. 6          List <the Entry <Integer, Goods >> listGoods = new new the ArrayList <> ();
 . 7          listGoods.addAll (setGoods);
 . 8          
. 9          // class sorted according to sales of the comparator 
10          the Collections.sort (listGoods, new new Comparator <the Entry <Integer, Goods >> () {
 . 11              @Override
 12 is             public  int Compare (the Entry <Integer, Goods> entry1, the Entry <Integer, Goods> entry2,) {
 13 is                  // order. . . 
14                  return entry1.getValue () getgHotCount () -. Entry2.getValue () getgHotCount ();.
 15              }
 16          });
 . 17          // print 
18 is          System.out.println ( "No \ t trade name \ t Product Number \ t sales of goods \ t commodity price " );
 . 19          for (the entry <Integer, goods> entry: listGoods) {
 20 is              System.out.println (entry.getValue ());
 21 is          }
 22 is      }
View Code

 

Guess you like

Origin www.cnblogs.com/zhf123/p/11665858.html