Jakarta Commons toString Builder
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
public class Main {
private String id;
private String firstName;
private String lastName;
public Main() {
}
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("id", id).append(
"firstName", firstName).append("lastName", lastName).toString();
}
public static void main(String[] args) {
Main example = new Main();
example.id = "1";
example.firstName = "First Name";
example.lastName = "Last Name";
System.out.println("example = " + example);
}
}
Related examples in the same category