title: How to display contents of an object in Java
body: <p>Ok, now I think I've given up all hope of finding solution to what should to be a simple problem. Basically, I'm creating a students' record system that stores students' details in an ArrayList. I first created a constructor in the Student class to specify what entries each student will have. I then created an instance of the Student class in the main class (i.e. class with the main method) and then added the student object to the studentList ArrayList. </p>
  
  <p>By the way, instead of hard-coding the student details, my initial aim was to let the user enter the details and then I'll use a Scanner or BufferedReader object to get the details stored in the Student object, and then to the ArrayList but I'm having trouble with that as well; so I'll probably tackle that problem as soon as I'm done with this one.</p>
  
  <p>Anyway, I'm expecting the output to print out the students' details but instead I get a memory location (i.e. [studentrecordsys.Student@15c7850]). I'm aware that I need to override the toString method but how exactly this is done is what I can't seem to get. I get syntax errors everywhere as soon as I enter the @Override code block for the toString method. Here's what I've tried:</p>
  
  <pre><code>import java.util.*;
  
  class Student {
      private String studentID;
      private String studentName;
      private String studentAddress;
      private String studentMajor;
      private int studentAge;
      private double studentGPA;
  
       Student (String studentID, String studentName, String studentAddress, String 
               studentMajor, int studentAge, double studentGPA){
  
          this.studentID=studentID;
          this.studentName=studentName;
          this.studentAddress=studentAddress;
          this.studentMajor=studentMajor;
          this.studentAge=studentAge;
          this.studentGPA=studentGPA;
       }
  }
  
  
  public static void main(String[] args) {
  Student ali = new Student("A0123", "Ali", "13 Bond Street", "BSc Software Engineering", 22, 3.79);
      List&lt;Student&gt; studentList = new ArrayList&lt;&gt;();
  
      studentList.add(ali);
  
      @Override
      String toString() {                        
          StringBuilder builder = new StringBuilder();
          builder.append(ali).append(studentList);
          return builder.toString();
      }
  
      System.out.println(builder);
  }
  </code></pre>