I have an assignment where we are required to create a User class with a toString() method. The toString method should return a string with all the information about the user. We are required to create an array of 50 User objects and print the information about each user on a separate line. The problem is, I want to keep everything in a neat table with all Strings of the same length. So for instance:
User Name Password Full Name Email
___________________________________________________________________________________________
shortUser 12345 John Smith [email protected]
thisUserIsLonger 1234567890 Smitty Werbenjagermanjensen [email protected]
I would like to keep everything aligned as it is in the above table. This would be easy in C++ since I could just use setw() to dynamically pad spaces between according to the size of the field. Is something like this possible in Java?
I know this may not be the exact thing you are looking for, but if you were comfortable with printf and its siblings, take a look at the String.format()
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