sorry for asking another really obvious question – I’m struggling with hashmaps..
What I want to do is change the order of where a value is stored in a list that is stored in a hashmap, and I do not want to use an iterator.
for example, there is a list of courses at a school and in each course there is a list of students. There the hall monitor job is the first student on list for a course that is picked at random. When a course is selected the student at the top of the list is then put to the bottom of the list for all the course that they are part of. There are 9 courses and and a student can appear on multiple student lists.
I’m trying to do something along the lines of:
//instance variable
private HashMap<String, String[]> qualifiedStudents;
qualifiedStudents = new HashMap<String, List<String>>();
public void putStudentLastInRosters(String studentName)
{
for(String course : qualifiedStudents.keySet())
{
if(qualifiedStudents.get(course).contains(studentName))
{
qualifiedStudents.remove(course, studentName);
qualifiedStudents.put(course, studentName);
}
}
}
Try this: