Java Long - toString() Method
The java.lang.Long.toString() method returns a string representation of the first argument in the radix specified by the second argument. If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.
Syntax
public static String toString(long i, int radix)
Parameters
i |
Specify the long to be converted. |
radix |
Specify the radix to use in the string representation. |
Return Value
Returns a string representation of the argument in the specified radix.
Exception
NA.
Example:
In the example below, the java.lang.Long.toString() method returns a String object representing the given long argument using specified radix.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating a long value long x = 111; //printing the long value System.out.println("The long value is: " + x); //creating and printing the string representation //of the long value using different radix System.out.println("The x in binary is: " + Long.toString(x, 2)); System.out.println("The x in octal is: " + Long.toString(x, 8)); System.out.println("The x in hexadecimal is: " + Long.toString(x, 16)); } }
The output of the above code will be:
The long value is: 111 The x in binary is: 1101111 The x in octal is: 157 The x in hexadecimal is: 6f
❮ Java.lang - Long