• + 1 comment

    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);
    	}