Guest User

Untitled

a guest
Oct 14th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.nio.file.Files;
  4. import java.nio.file.Paths;
  5. import java.util.Comparator;
  6.  
  7. public class Pr04SortStudents {
  8.  
  9.     public static void main(String[] args) {
  10.         final String dataFile = "src\\Lesson07BuiltInQueryMethodsStreamAPI\\Resources\\StudentData.txt";
  11.  
  12.         try (BufferedReader br = Files.newBufferedReader(Paths.get(dataFile))) {
  13.             br.lines()
  14.                     .skip(1)
  15.                     .map(line -> line.split("\\s+"))
  16.                     .sorted(Comparator
  17.                             .comparing((String[] x) -> x[2])
  18.                             .thenComparing((x, y) -> y[1].compareTo(x[1]))
  19.                     )
  20.                     .map(x -> x[1] + " " + x[2])
  21.                     .forEach(System.out::println);
  22.         } catch (IOException e) {
  23.             e.printStackTrace();
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment