I'm creating a program where I have to make a database for an university. I used a map to save data and I need to sort it by attribute course to show the name and the code of the subject, but I don't know how to do it. Thanks a lot!
 public class Student {
    private String apellido = "";
    private String nombre = "";
    private String correo = "";
    private String dni = "";
    public Student(String lastname, String name, String mail, String id)                
    {
        this.lastname = lastname;
        this.name = name;
        this.mail = mail;
        this.id = id;
    }
}
public class Subject {
    private String name = "";
    private int code
    private int course;
    public Subject(String name, int code, int course) {
        this.name = name;
        this.code = code;
        this.course = course;
    }
    public String getName() {
        return name;
    }
    public int getCode() {
        return code;
    }
    public int getCourse() {
        return course;
    }
}
public class Model {
private Map<Subject, List<Student>> map = new HashMap<>();
    public void orderByCourse() {
    System.out.printf("%-20s %-6s\n", "subject", "code");
    List<String> list = new ArrayList<String>();
    for (Entry<Subject, List<Student>> element : map.entrySet()){
        Subject key = element.getKey();
        List<Student> value = element.getValue();
        System.out.printf("%-20s %-6s\n", key.getName(), key.getCode());
    }
}
 
     
    