KeepCoding

Need help with saving the result of a stream

Jul 4th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import abstractClasses.Car;
  2. import classes.PerformanceCar;
  3. import classes.ShowCar;
  4.  
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.util.ArrayList;
  9. import java.util.LinkedHashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.stream.Collectors;
  13.  
  14. public class Main {
  15.     public static void main(String[] args) throws IOException {
  16.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  17.  
  18.         Map<String, Integer> personPoints = new LinkedHashMap<>();
  19.         personPoints.put("Gosho", 100);
  20.         personPoints.put("Tosho", 23);
  21.         personPoints.put("Sasho", 1);
  22.         personPoints.put("Pesho", 5);
  23.         personPoints.put("Esho", 5);
  24.         reader.close();
  25.  
  26.         personPoints = personPoints.entrySet().stream().sorted((x1, x2) -> {
  27.             return x2.getValue().compareTo(x1.getValue());
  28.         }).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
  29.  
  30.         //result of personPoints:
  31.         //"Pesho" -> "5"
  32.         //"Sasho" -> "1"
  33.         //"Esho" -> "5"
  34.         //"Tosho" -> "23"
  35.         //"Gosho" -> "100"
  36.  
  37.     }
  38.  
  39.    
  40. }
Add Comment
Please, Sign In to add comment