Java.lang Package Classes

Java Long - toString() Method



The java.lang.Long.toString() method returns a string representation of this Long object. The value is converted to signed decimal representation and returned as a string, exactly as if the long value were given as an argument to the toString(long) method.

Syntax

public String toString()

Parameters

No parameter is required.

Return Value

Returns a string representation of the value of this object in base 10.

Exception

NA.

Example:

In the example below, the java.lang.Long.toString() method returns a String object representing the given Long's value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Long object
    Long x = 25l;

    //printing the Long object 
    System.out.println("The Long object is: " + x); 

    //creating and printing the string representation
    //of the Long object's value
    String x_tostring = x.toString();
    System.out.println("The string value of Long is: " + x_tostring);   
  }
}

The output of the above code will be:

The Long object is: 25
The string value of Long is: 25

❮ Java.lang - Long