Java Convert Long to Hexadecimal String

Tags: long Hexadecimal

In this Java core tutorial we learn how to convert a long value into a hexadecimal String in Java programming language.

How to convert Long to Hex String in Java

In Java, with a given long value we can use the Long.toHexString(long i) static method to convert it to a hexadecimal String as the example Java code below.

public class ConvertLongToHexExample {
    public static void main(String... args) {
        long longValue = 999999;

        // Convert Long to Hexadecimal String
        String hexString = Long.toHexString(longValue);

        System.out.println("Long value: " + longValue);
        System.out.println("Hexadecimal String: " + hexString);
The output as below.
Long value: 999999
Hexadecimal String: f423f

Happy Coding 😊

Java Convert Hexadecimal String to Long

Java Convert Long to Octal String

Java Convert Octal String to Long

Java Convert long to byte