I’m using a HashMap in which I use an ArrayList as a value.
Like this:
Map<Movie, List<Grades>> gradedMovies = new HashMap();
I’m trying to create a method with which I could iterate through the values to see if a key(movie) already exists. If it does, I would like to add a new value(grade) into the list that is assigned to the particular key(movie). Something like this:
public void addGrade(Movie movie, Grade grade) {
// stuff here }
Ultimately I wan’t to be able to print a Map which would display the Movies and its’ grades after they’ve been added to the map.
How is this accomplished? Or is my whole approach (using a Map) totally wrong?
Thanks for any assistance. (This is homework)
I think you’re on the right path, just make sure your movie object implements
equalsandhashCodeso it can work as a true key for the hash map.If you want pretty printing just implement the toString method.
hope this helps, Cheers!