Java Priority Queue

  • + 2 comments

    To be honest, i have no idea why thats not working 😅

    class Priorities {
        public List<Student> getStudents(List<String> events) {
            PriorityQueue<Student> response = new PriorityQueue<>(
                Comparator.comparing(Student::getCGPA, Comparator.reverseOrder())
                        .thenComparing(Student::getName)
                        .thenComparing(Student::getID));
    
            for (String event : events) {
                if (!event.contains("ENTER")) {
                    response.poll();
                    continue;
                }
                String[] split = event.split(" ");
                Integer id = Integer.valueOf(split[3]);
                Double cgpa = Double.valueOf(split[2]);
    
                Student student = new Student(id, split[1], cgpa);
    
                response.add(student);
            }
    			
    
            return response.stream().collect(Collectors.toList());
        }
    }