Check out example codes for "tostring method in java". It will help you in understanding the concepts better.

Code Example 1

// Java program to illustrate 
// working of toString() method 
class Best_Friend { 
    String name; 
    int age; 
    String college; 
    String course; 
    String address; 
    Best_Friend 
    (String name, int age, String college, String course, String address) 
    { 
        this.name = name; 
        this.age = age; 
        this.college = college; 
        this.course = course; 
        this.address = address; 
    } 
public String toString() 
    { 
        return name + " " + age + " " + college + " " + course + " " + address; 
    } 
public static void main(String[] args) 
    { 
        Best_Friend b =  
        new Best_Friend("Gulpreet Kaur", 21, "BIT MESRA", "M.TECH", "Kiriburu"); 
        System.out.println(b); 
        System.out.println(b.toString()); 
    } 
}

Code Example 2

public String toString()
{
      return getClass().getName()+"@"+Integer.toHexString(hashCode());
}

Code Example 3

public class Test { 

   public static void main(String args[]) {
      Integer x = 5;

      System.out.println(x.toString());  
      System.out.println(Integer.toString(12)); 
   }
}

Learn ReactJs, React Native from akashmittal.com