This may sound very basic… can someone please explain the use of the toString() method and when to effectively use this?
Have done a search on google but could not find any good resource.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In most languages,
toStringor the equivalent method just guarantees that an object can be represented textually.This is especially useful for logging, debugging, or any other circumstance where you need to be able to render any and every object you encounter as a string.
Objects often implement custom
toStringbehavior so that the method actually tells you something about the object instance. For example, aPersonclass might override it to return “Last name, First name” while aDateclass will show the date formatted according to some default setting (such as the current user interface culture).