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

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

193 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements