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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 26-Dec-2018 15:40:38
Advertisements