Results 1 to 3 of 3
Thread: toString() method
- 03-25-2009, 03:45 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
toString() method
I'm overriding the toString() method for a Polygon class. An instance of Polygon has n points (i.e the number of points varies). These points are stored in an array of points, how do I convert these points to a string representation when the number of points is different for each instance of the Class? Is there some way of recursively doing this?
- 03-25-2009, 04:02 PM #2
Member
- Join Date
- Mar 2009
- Location
- Germany
- Posts
- 22
- Rep Power
- 0
You could try it like that
evenJava Code:Point[] points; ... // Returns "2:(1,2):(2,3)", if your point's toString methode returns "(x,y)" public String toString() { String s = points.length; for(Point p : points) { s += ":" + p.toString(); } return points; }
is possible.Java Code:public String toString() { return points.toString(); }
I wouldn't go for any recursion.
- 03-25-2009, 11:43 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 25
- Rep Power
- 0
Similar Threads
-
toString question
By mayhewj7 in forum New To JavaReplies: 1Last Post: 01-29-2009, 07:41 PM -
question about writing a toString method
By heather.diggs in forum New To JavaReplies: 2Last Post: 11-12-2008, 11:13 PM -
toString() method of java.security.MessageDigest
By Nicholas Jordan in forum Advanced JavaReplies: 4Last Post: 09-18-2008, 02:32 PM -
toString method
By apfroggy0408 in forum New To JavaReplies: 6Last Post: 01-31-2008, 04:08 AM -
Can i just use toString?
By cachi in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks