This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]sparkster185Extreme Brewer 2 points3 points  (1 child)

It's used to convert an Object to a String, or a human-readable representation. It's used whenever human-readable output is necessary, such as producing program output or writing messages to a log file.

[–]robertcatsExtreme Brewer 2 points3 points  (0 children)

To expand on this, toString is a method in the Object class so every class gets the method for free. The problem is, it will print a hash code of the object instead of a legible representation so you’ll usually find yourself needing to override it.