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);
        }
    }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.