Home » Java programming language

Java Integer class toOctalString() method with example

Integer class toOctalString() method: Here, we are going to learn about the toOctalString() method of Integer class with its syntax and example.
Submitted by Preeti Jain, on September 28, 2019

Integer class toOctalString() method

  • toOctalString() method is available in java.lang package.
  • toOctalString() method is used to represent an octal string of the given parameter [value] of integer type as an unsigned integer in base 8.
  • toOctalString() method is a static method, it is accessible with class name too and if we try to access the method with the class object then also we will not get an error.
  • toOctalString() method does not throw an exception at the time of conversion from integer to an octal string.


    public static String toOctalString (int value);


  • int value – represents the integer value to be converted.

Return value:

The return type of this method is int, it returns the octal string of the given parameter that represent the unsigned integer value.


// Java program to demonstrate the example 
// of toOctalString (int value) method of Integer class

public class ToOctalStringOfIntegerClass {
    public static void main(String[] args) {
        // Variables initialization
        int i1 = 10;
        int i2 = 20;
        int i3 = 30;
        int i4 = Integer.MAX_VALUE;
        int i5 = Integer.MIN_VALUE;

        // Integer instance creation
        Integer value = new Integer(i1);

        // It represents Octal string of the given
        // integer type i2 argument
        String s = value.toOctalString(i2);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i2): " + s);

        // It represents Octal string of the given
        // integer type i3 argument
        s = value.toOctalString(i3);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i3): " + s);

        // It represents Octal string of the given
        // integer type i4 argument
        s = value.toOctalString(i4);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i4): " + s);

        // It represents Octal string of the given
        // integer type i5 argument
        s = value.toOctalString(i5);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i5): " + s);


value.toOctalString(i2): 24
value.toOctalString(i3): 36
value.toOctalString(i4): 17777777777
value.toOctalString(i5): 20000000000

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.