Java Convert Long to Octal String

Tags: long Octal

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

How to convert Long to Octal String in Java

In Java, with a given long value we can use the Long.toOctalString(long i) static method to convert it to an octal String as the following example Java code.

ConvertLongToOctalExample.java

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

        // Convert Long to Octal String
        String octalString = Long.toOctalString(longValue);

        System.out.println("Long value: " + longValue);
        System.out.println("Octal value: " + octalString);
    }
}
The output as below.
Long value: 999999
Octal value: 3641077

Happy Coding 😊

Java Convert Long to Hexadecimal String

Java Convert Hexadecimal String to Long

Java Convert Octal String to Long

Java Convert long to byte