Hi,
Can anyone tells me what method I should use to align the output?
I am searching but can't find anything.
thank you :)
Printable View
Hi,
Can anyone tells me what method I should use to align the output?
I am searching but can't find anything.
thank you :)
You may wish to describe your problem in greater detail as the answer will depend upon the requirements. Is this a Swing app with output in a JTextField? A console app?
If the latter, then you might want to look at System.out.printf(...) method or String.format(...). They both do the same thing. You'll have to read the tutorial and API several times to "get" this (I know that I had to on the first go-around), but it's eventually worthwhile reading.
Thanks for your prompt answer.
I just realized how vague my question was! Sorry about that.
I am printing(outputing) from a string linkedList both in a console and in a text file.
I need to output each String(word), with different lengths, along with a corresponding #
so my output now looks like:
firstWord 1
anotherWord 2
word 3
but I want it to be aligned:
firstWord 1
anotherWord 2
word 3
could I use tab (\t) somehow or do I need to use a method?
tell me which tutorials I need to read for this and I'd be willing to do that , thanks :)
Have a look here:
Formatting (The Java™ Tutorials > Essential Classes > Basic I/O)
And here:
Formatter (Java Platform SE 6)
I have looked at both links but they talk about formatting numbers.
I didn't see an example of what I want there :(
I need to format the output sting by adding a tab or 2 after each string or something like that!
They format Strings too. Read them again. You use %XXs where XX is some number for Strings. Again, read again.