We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.*;importjava.util.stream.Collectors;classStudent{privateintid;privateStringfname;privatedoublecgpa;publicStudent(intid,Stringfname,doublecgpa){super();this.id=id;this.fname=fname;this.cgpa=cgpa;}publicintgetId(){returnid;}publicStringgetFname(){returnfname;}publicdoublegetCgpa(){returncgpa;}}//Complete the codepublicclassSolution{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);inttestCases=Integer.parseInt(in.nextLine());List<Student>studentList=newArrayList<Student>();while(testCases>0){intid=in.nextInt();Stringfname=in.next();doublecgpa=in.nextDouble();Studentst=newStudent(id,fname,cgpa);studentList.add(st);testCases--;}studentList.stream().sorted(Comparator.comparing(Student::getCgpa).reversed().thenComparing(Student::getFname).thenComparing(Student::getId)).forEach(student->{System.out.println(student.getFname());});}}
Java Sort
You are viewing a single comment's thread. Return to all comments →