Convert Long into String using toString() method of Long class in java


The toString() method gives string representation to a Long. Let’s say we have the following Long object −

Long longObj = new Long(70);
System.out.println("Long: " + longObj);

To convert it to String, the toString() method is used −

String myStr = longObj.toString();

The following is the complete example −

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      // Long
      Long longObj = new Long(70);
      System.out.println("Long: " + longObj);
      // conversion
      String myStr = longObj.toString();
      System.out.println("Converted to String: " + myStr);
   }
}

Output

Long: 70
Converted to String: 70

Updated on: 30-Jul-2019

136 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements