Convert Long to 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: 2019-07-30T22:30:24+05:30

165 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements