Java: Print content from HashMap<String, Object> : <p>I need to print all the contents from the <code>HashMap&lt;String, StudentSchedule&gt;</code> where StudentSchedule is a class that store other objects. In the StudentSchedule, there is a function that prints out some data which I want it to print when the HashMap is printing. I have used the enhanced for loop to print the HashMap, but the values are like object Number. When the values are printing, i want it to print the function that is in StudentSchedule.printSchedule(). I am not sure if that is possible. I think I have made it more complicated that it should be but here is what I have so far:</p>

<pre><code>public class StudentSchedule {
    private Student student;
    private Course course;

    private String[] courseDays;
    private String[] courseTimes;

    public StudentSchedule(Student student, Course course, String[] courseDays, String[] courseTimes) {
        this.student = student;
        this.course = course;
        this.courseDays = courseDays;
        this.courseTimes = courseTimes;
    }

    public Student getStudent() {
        return student;
    }

    public Course getCourse() {
        return course;
    }

    public String[] getCourseDays() {
        return courseDays;
    }

    public String[] getCourseTimes() {
        return courseTimes;
    }

    public void printSchedule() {
        System.out.println("\nClass Schedule");
        String studentInfo = getStudent().toString();
        String courseInfo = getCourse().toString();
        String[] courseDays = getCourseDays();
        String[] courseTimes = getCourseTimes();

        if(courseDays[2] != null &amp;&amp; courseTimes[2] != null) {
           System.out.println(studentInfo + "\n" + courseInfo + "\n" + 
           courseDays[0] + " -&gt; " + courseTimes[0] + "\n" + 
           courseDays[1] + " -&gt; " + courseTimes[1] + "\n" + 
           courseDays[2] + " -&gt; " + courseTimes[2]);
        }
        else {
           System.out.println(studentInfo + "\n" + courseInfo + "\n" + 
           courseDays[0] + " -&gt; " + courseTimes[0] + "\n" + 
           courseDays[1] + " -&gt; " + courseTimes[1]);
        }
    }
}
</code></pre>

<p>ScheduleManager</p>

<pre><code>public class ScheduleManager
{
    private HashMap&lt;String, StudentSchedule&gt; allStudentSchedule = new HashMap&lt;&gt;();

    public void createSchedule() {
        Student newStudent = getStudentInfo();
        Course newCourse = getCourseInfo();
        courseDays = getCourseDays();
        courseTimes = getCourseTimes(courseDays);
        studentSchedule = new StudentSchedule(newStudent, newCourse, courseDays, courseTimes);
        allStudentSchedule.put(newStudent.getStudentId(), studentSchedule);
        // testing print schedule
        studentSchedule.printSchedule();
    }

    private void displaySchedule() {
        Set&lt;Entry&lt;String,StudentSchedule&gt;&gt; hashSet = allStudentSchedule.entrySet();
            for(Entry entry : hashSet ) {
            System.out.println("Key="+entry.getKey()+",     Value="+entry.getValue());
        }

    }
....
</code></pre>
