title: How do I print my Java object without getting "SomeType@2f92e0f4"?
body: <p>I have a class defined as follows:</p>
  
  <pre><code>public class Person {
    private String name;
  
    // constructor and getter/setter omitted
  }
  </code></pre>
  
  <p>I tried to print an instance of my class:</p>
  
  <pre><code>System.out.println(myPerson);
  </code></pre>
  
  <p>but I got the following output: <code>com.foo.Person@2f92e0f4</code>.  </p>
  
  <p>A similar thing happened when I tried to print an array of <code>Person</code> objects:</p>
  
  <pre><code>Person[] people = //...
  System.out.println(people); 
  </code></pre>
  
  <p>I got the output: <code>[Lcom.foo.Person;@28a418fc</code></p>
  
  <p>What does this output mean? How do I change this output so it contains the name of my person? And how do I print collections of my objects?</p>
  
  <p><sub><strong>Note</strong>: this is intended as a canonical Q&amp;A about this subject.</sub></p>