Java.lang.Long.toString() Method


Description

The java.lang.Long.toString(long i, int radix) method returns a string representation of the first argument i in the radix specified by the second argument radix.If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead. The following ASCII characters are used as digits: 0123456789abcdefghijklmnopqrstuvwxyz

Declaration

Following is the declaration for java.lang.Long.toString() method

public static String toString(long i, int radix)

Parameters

  • i − This is a long to be converted.

  • radix − This is the radix to use in the string representation.

Return Value

This method returns a string representation of the argument in the specified radix.

Exception

NA

Example

The following example shows the usage of java.lang.Long.toString() method.

package com.tutorialspoint;

import java.lang.*;

public class LongDemo {

   public static void main(String[] args) {

      Long l = new Long(5);
   
      // returns a string representation of the specified long with radix 10
      String retval = l.toString(87630, 10);
      System.out.println("Value = " + retval);

      // returns a string representation of the specified long with radix 16
      retval = l.toString(87630, 16);
      System.out.println("Value = " + retval);

      // returns a string representation of the specified long with radix 8
      retval = l.toString(87630, 8);
      System.out.println("Value = " + retval);
   }
}  

Let us compile and run the above program, this will produce the following result −

Value = 87630
Value = 1564e
Value = 253116
java_lang_long.htm
Advertisements