Merging HashMaps

Discussion in 'Java' started by psmith@mcwy.com, Mar 12, 2007.

  1. Guest

    I have to merge two hashmaps, one results (contains grades), the other
    students(contains students, with exam results. Their exam marks are
    averaged out and graded. I need the students to appear in the results
    hashmap against their grade, can somebody please point out what is
    wrong with the following:

    public void collateResults()
    {
    char grades[] = {'A', 'B', 'C', 'D', 'F', 'X'};
    {
    for (Character grade : grades)
    {
    this.results.put(grade, new HashSet<String>());
    }
    for (String eachStudent : students.keySet())
    {
    for(String graded : this.results.get(eachStudent))
    {
    this.results.get(graded).add(eachStudent);
    }
    }
    }
    }

    Any help greatly appreciated.

    Paul
    , Mar 12, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maps and Hashmaps

    , May 25, 2004, in forum: Java
    Replies:
    2
    Views:
    2,429
    jAnO!
    May 25, 2004
  2. Marilyn Hart

    Help on Hashmaps

    Marilyn Hart, Jan 22, 2005, in forum: Java
    Replies:
    5
    Views:
    603
    Bjorn Abelli
    Jan 23, 2005
  3. Roedy Green

    HashCodes and HashMaps

    Roedy Green, Sep 20, 2005, in forum: Java
    Replies:
    2
    Views:
    473
    Roedy Green
    Sep 20, 2005
  4. Siam
    Replies:
    4
    Views:
    1,161
    Eric Sosman
    Dec 30, 2006
  5. Merging HashMaps

    , Mar 12, 2007, in forum: Java
    Replies:
    3
    Views:
    8,665
    Gagan
    Mar 13, 2007
Loading...

Share This Page