I'm deconstructing a Java object, taking all the required String values from the getters and concatenating all these into one String per object. I then i want to store each string is an
ArrayList<String>
I'm concatenating the strings into one string per object so i can print it out in a pdf document (pdfbox) for a report... I want to format each row to be the identical as if in a table. E.g regardless if the String1 is 3 characters or 103 characters long it will always fill 25 characters space --either substring to make smaller or buffered with space to make larger depending on what's required.
My question is how to do this efficiently? For this example lets say I require that every entry is 25 characters long. So for each value I'm appending below how do i enforce that all entries are 25 chars long?
String SPACE=" ";
for(People peeps: list){
builder = new StringBuilder();
name =(peeps.getName());
// if(name.length()>25){name=name.substring(0,25);}
builder.append(name)
.append(SPACE)
.append(peeps.getCode())
.append(SPACE)
.append(peeps.getReference())
.append(SPACE)
.append(peeps.getDate())
.append(SPACE)
.append(peeps.getStatus())
.append(SPACE)
.append(peeps.getValue());
reportList.add(builder.toString());
}
e.g