Java.lang Package Classes

Java Long - toHexString() Method



The java.lang.Long.toHexString() method returns a string representation of the long argument as an unsigned integer in base 16.

Syntax

public static String toHexString(long i)

Parameters

i Specify a long to be converted to a string.

Return Value

Returns the string representation of the unsigned long value represented by the argument in hexadecimal (base 16).

Exception

NA.

Example:

In the example below, the java.lang.Long.toHexString() method returns a string representation of the long argument as an unsigned integer in base 16.

import java.lang.*;

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

    //creating and printing string representation of 
    //argument in hexadecimal system.
    System.out.println("x in hexadecimal system is: " + Long.toHexString(x)); 
    System.out.println("y in hexadecimal system is: " + Long.toHexString(y)); 
    System.out.println("z in hexadecimal system is: " + Long.toHexString(z));   
  }
}

The output of the above code will be:

x in hexadecimal system is: 19
y in hexadecimal system is: 1f
z in hexadecimal system is: 6f

❮ Java.lang - Long