Wednesday, March 19, 2014

Override toString() method with ToStringBuilder

One fancy way of toString method implementation is in using of ToStringBuilder class.
With this class you don't need to specify all the objects for output and you get a flexible mechanism of building and formatting your object's string representaion.
Just a couple of strings:


import org.apache.commons.lang.builder.ToStringBuilder;

public String toString() {
return ToStringBuilder.reflectionToString(this);

Got it!

See more information on official reference documntation:

Another very good article about ToStringBuilder by Lokesh Gupta (with nice samples)