Java Data Type How to - Convert decimal integer to octal value string








Question

We would like to know how to convert decimal integer to octal value string.

Answer

public class Main {
  public static void main(String[] args) {
    int i = 27;

    String strOctalNumber = Integer.toOctalString(i);
    System.out.println(strOctalNumber);
  }
}

The code above generates the following result.