Java.lang Package Classes

Java Long - toString() Method



The java.lang.Long.toString() method returns a String object representing the specified long. The argument is converted to signed decimal representation and returned as a string, exactly as if the argument and the radix 10 were given as arguments to the toString(long, int) method.

Syntax

public static String toString(long i)

Parameters

i Specify the long to be converted.

Return Value

Returns a string representation of the argument in base 10.

Exception

NA.

Example:

In the example below, the java.lang.Long.toString() method returns a String object representing the given long argument.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating a long value
    long x = 25;

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

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

The output of the above code will be:

The long value is: 25
The string value of long is: 25

❮ Java.lang - Long