Search results
Results From The WOW.Com Content Network
Java toString () Method. If you want to represent any object as a string, toString () method comes into existence. The toString () method returns the String representation of the object. If you print any object, Java compiler internally invokes the toString () method on the object.
Commonly used for diagnostic purposes like debugging, logging etc., the toString () method is used to read meaningful details about the object. It is automatically invoked when the object is passed to println, print, printf, String.format (), assert or the string concatenation operator.
The toString() method of Byte class is a built in method in Java which is used to return a String value. public String toString() Syntax: ByteObject.toString() Return Value: It returns a String object, the value of which is equal to the value of the ByteObject.
The toString() method returns the string itself. This method may seem redundant, but its purpose is to allow code that is treating the string as a more generalized object to know its string value without casting it to String type.
And since the Object class contains a toString() method, we can call toString() on any instance and get its string representation. In this tutorial, we’ll look at the default behavior of toString() and learn how to change its behavior.
The most straightforward way to convert an object to a string is by using the toString() method. toString() is a built-in method provided by the Obje ct class, which is the root class for all Java objects .
The toString() method is a built-in Java method that returns a string representation of an object. By default, the toString() method returns a string that consists of the class name, the @ symbol, and the hashcode of the object in hexadecimal format.