What is the purpose of toString() method? Or What does the toString() method do in java?


The toString() method returns the current object in String format.

Example

Live Demo

public class Test {
public static void main(String args[]) {
Test obj = new Test();
System.out.println(obj.toString());
System.out.println("Hello");
}
}

Output

Test@2a139a55
Hello

Updated on: 19-Feb-2020

142 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements