I have several java objects with four string properties as below:
For e.g. say object1 is having values as
String one = "abcd"; //length 4
String two = "efghij"; //length 6
String three = "klmnop"; //length 6
String four = "qrs"; //length 3
I want to output above data in to a fixed format file.
The format would be: one is 10 characters, two is 8 characters, three is 9 characters, four is 10 characters.
So above example will be as:
6spaces+abcd+2spaces+efghij+3spaces+klmnop+6spaces+qrs
Thus what I want to achieve is convert each strings to the appropriate length as required by the file and then push those to the file.
How to achieve this most efficiently ??
The simplest way is propably to use
String.format().The description of the format syntax can be found here.