Home How do I print my Java object without getting "SomeType@2f92e0f4"?
Reply: 0

How do I print my Java object without getting "SomeType@2f92e0f4"?

user846
1#
user846 Published in July 22, 2018, 8:33 am

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:

System.out.println(myPerson);

but I got the following output: com.foo.Person@2f92e0f4.

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

Person[] people = //...
System.out.println(people); 

I got the output: [Lcom.foo.Person;@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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.471781 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO