Comment puis-je ajouter une valeur à un ensemble de hachage?

Je suis en train de travailler sur un problème pratique qui m'oblige à ajouter une valeur dans une table de hachage. Mais je ne peux pas comprendre pourquoi je reçois un message d'erreur sur la ligne courseName.add(student);

Voici mon code:

public class StudentDatabase {

    //add instance variables
    private Map<String, HashSet<Integer>> dataContent = new LinkedHashMap<String, HashSet<Integer>>();

    //Prints a report on the standard output, listing all the courses and all the
    //students in each.  If the map is completely empty (no courses), prints a message
    //saying that instead of printing nothing.
    public void report() {
        if (dataContent.isEmpty()) {
            System.out.println("Student database is empty.");
        } else {
            for (String key : dataContent.keySet()) {
                System.out.println(key + ":" + "\n" + dataContent.get(key));
            }
        }
    }

    //Adds a student to a course.  If the student is already in the course, no change
    //If the course doesn't already exist, adds it to the database.
    public void add(String courseName, Integer student) {
        if (dataContent.containsKey(courseName)) {
            courseName.add(student);
        } else {
            Set<Integer> ids = new HashSet<Integer>();
            ids.add(student);
            dataContent.put(courseName, ids);
        }
    }
}
Le titre de cette question n'a pas de sens. La méthode qui êtes-vous essayer de modifier? Le Map JavaDoc couvre toutes les opérations que vous pourriez avoir besoin (et il n'y en a pas beaucoup!). Vous êtes presque certainement à la recherche pour Map#put(). La partie ne comprenez-vous pas?

OriginalL'auteur user2259968 | 2013-04-09