I'm trying to write a method that displays the contents of a hashmap on screen. This hashmap contains Strings and an array of int for every String. I've put the String aspects of the hashmap into an arraylist and I'm trying to use another method to print the arrays for each String. I've tried the two methods above as well as some variations on the two and in all attempts when I try to print the marks, I get something like "I@1d501268" rather then an actual String. I assume this means that the array hasn't been correctly translated into a String that can be printed. So my question is where have I gone wrong here?

public void showQuizMarks()
    {
        ArrayList<String> students = new ArrayList<String>(quizMarks.keySet());
        for (String eachStudent: students) {
            System.out.println ("Quiz marks for: " + eachStudent);
            System.out.print (getQuizzes(eachStudent));
        }
    }

    public int[] getQuizzes(String student)
    {
        int[] studentMark = quizMarks.get(student);
        return studentMark;
    }

    public void showQuizMarksVersion2()
    {
        ArrayList<String> students = new ArrayList<String>(quizMarks.keySet());
        for (String eachStudent: students) {
            int[] studentMark = getQuizzes(eachStudent);
            String score = studentMark.toString();
            System.out.println ("Quiz marks for: " + eachStudent);
            System.out.print (score);
        }
    }

Edited 4 Years Ago by peter_budo: Please do not use code snippets to post questions

You haven't gone wrong, the strange String you see is the default toString method that everything inherits from Object ( [ = array, I = int, @xxx = hash code ). The easiest way to print the contents of an array is with the Arrays.toString(myArray) method.

This article has been dead for over six months. Start a new discussion instead.