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

Name                      Age               other stuff            more stuff
-------------------------------------------------------------------------------
Bob Someguy                42                   blabado                   3.14
Guy Two                    38                   dododod                   1234

nice neat columns n' stuff...
I appreciate any thoughts...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.