*
The moose likes Beginning Java and the fly likes regarding toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "regarding toString()" Watch "regarding toString()" New topic
Author

regarding toString()

Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
Dear all,

I have a class called

student(name, age, address, class).

I need to do 2 operations( display and print to file)

I need to display using toString().
However, the problem comes when I need to print into file in this order
class + name + address + age.

Is there a profesional way to reuse the toString()?? instead of duplicate the code again?

Thanks alot
Steve Simon Joseph Fernandez
Ranch Hand

Joined: Jul 17, 2005
Posts: 35
Hi,

I don't think so; in your case, the order of the variables being printed to screen is different from the order in which they should be written to the file (if I've understood your question correctly)

_steve.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

As Steve said, it appears that you require two different Strings (with different ordering of elements). So although these Strings are constructed in a similar manner, this isn't really a "duplication" of code -- it's 2 distinct things.
[ August 22, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding toString()
 
Similar Threads
memory address of object
Reading arrays
Hide part of text on JLabel
Sorting ArrayList with Comparitor Interface for String property
How to search a Vector array?