I am writing to a file in java but the strings that are input into the file are different, how do i adjust the trailing whitespace depending on the length of the string.
for example
First Name Last Name Address
---------- --------- -------
Michael Jordan 23 E. Jump Street
Larry Bird 33 North Celtics Run
You can use String.format():
System.out.println(String.format("[%-20s]", "foo"));
will give you:
[foo ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With