Java Convert Octal String to Integer

Tags: Octal Integer

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

How to convert octal String to Integer in Java

In Java, with given String in octal number format we can use the Integer.decode(String nm) static method to convert it to an Integer value as the following Java code.

ConvertOctalToIntegerExample.java

public class ConvertOctalToIntegerExample {
    public static void main(String... args) {
        String octalValue1 = "0200";
        String octalValue2 = "0400";

        // Convert Octal String to Integer
        int intValue1 = Integer.decode(octalValue1);
        int intValue2 = Integer.decode(octalValue2);

        System.out.println("octalValue1: " + octalValue1);
        System.out.println("intValue1: " + intValue1);
        System.out.println("\noctalValue2: " + octalValue2);
        System.out.println("intValue2: " + intValue2);
    }
}
The output as below.
octalValue1: 0200
intValue1: 128

octalValue2: 0400
intValue2: 256

Happy Coding 😊

Java Convert Octal String to short

Java Convert short to Octal String

Java Convert Integer to Octal String