Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
The toString method is a built-in method in Java that converts an object into a string representation. It returns a string that represents the value of the object.
Related terms
equals method: The equals method is another built-in method in Java that compares two objects for equality. It returns true if the objects have the same values, and false otherwise.
getClass method: The getClass method is used to get the class (type) of an object at runtime. It returns an instance of Class, which provides information about the class.
hashCode method: The hashCode method is used to get a unique identifier (hash code) for an object. It returns an integer value that represents the object's internal memory address.