I have a Hashmap that stores a student name as the key and an int array of scores as the value. I know its creating the HashMap correctly but when trying to return the int array for a key I cant seem to get.
public int[] getQuizzes(String studentName)
{
int[] studentsQuizzes = quizMarks.get(studentName);
return studentsQuizzes;
}
It just ends up returning null. What am I missing, thanks for any help
This is how I am creating the hashmap
quizMarks = new HashMap<String, int[]>();
public void addStudent(String studentName)
{
String formattedName = formatName(studentName);
int[] quizzes = new int[NUM_QUIZZES];
for (int i = 0; i < quizzes.length; i++)
{
quizzes[i] = MIN_GRADE;
}
quizMarks.put(formattedName, quizzes);
}
Your keys in the map are the results of calling
formatNameon the student name passed in. You don’t appear to be using the formatted name as the key when callinggeton the map, meaning the keys you pass togetare not the same as those you passed toput.