Reputation: 21
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);
}
Upvotes: 0
Views: 2555
Reputation: 110054
Your keys in the map are the results of calling formatName
on the student name passed in. You don't appear to be using the formatted name as the key when calling get
on the map, meaning the keys you pass to get
are not the same as those you passed to put
.
Upvotes: 4