Garmaine Staff asked 5 years ago

I have a class defined as follows:

public class Person {
  private String name;

  // constructor and getter/setter omitted

I tried to print an instance of my class:


but I got the following output:

A similar thing happened when I tried to print an array of Person objects:

Person[] people = //...

I got the output: [;@28a418fc

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?

Note: this is intended as a canonical Q&A about this subject.