954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

toString format help

Dear god. this is driving me crazy. I'm working on an assignment involving inheritence, multiple classes, etc. I'm stuck at one stupid part. I have to write a toString method that formats the text. Is there a way to return a string with formatted text? I know about the printf method, and I can get that to work fine, but just with System.out.printf... I don't know how to return a formatted string.. Is it even possible?

What i need is I have someones name, first and last, then their age, but the ages of the people have to line up in a column. Make sense? The names & ages are one object, & the multiple people are in array of people objects... so i have a for loop that will go through and print each person one at a time. So how do i pad the age correctly & return it to the calling method?

I would just say forget returning the string and just simply print it out, but I need the same method elsewhere to write to a file also.

so, what i need to end up with is something that looks like this

[html]
Name Age other stuff more stuff
-------------------------------------------------------------------------------
Bob Someguy 42 blabado 3.14
Guy Two 38 dododod 1234
[/html]
nice neat columns n' stuff...
I appreciate any thoughts...

bondo
Light Poster
45 posts since Apr 2007
Reputation Points: 11
Solved Threads: 0
 

BLAH! Ok, i should've done a search first. I found my answer.

For anyone else who need's help on this same thing, here's the thread I found:

http://www.daniweb.com/techtalkforums/showthread.php?t=56466

bondo
Light Poster
45 posts since Apr 2007
Reputation Points: 11
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You