You are viewing a single comment's thread. Return to all comments →
May as well go all the way and use a stream
public class Solution { public static void main(String[] args){ Scanner in = new Scanner(System.in); int testCases = Integer.parseInt(in.nextLine()); List<Student> studentList = new LinkedList<Student>(); while(testCases>0){ int id = in.nextInt(); String fname = in.next(); double cgpa = in.nextDouble(); Student st = new Student(id, fname, cgpa); studentList.add(st); testCases--; } studentList.stream().sorted( Comparator.comparing(Student::getCgpa).reversed() .thenComparing(Student::getFname) .thenComparing(Student::getId)) .map(Student::getFname).forEach(System.out::println); }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Sort
You are viewing a single comment's thread. Return to all comments →
May as well go all the way and use a stream