Java - Long Class toOctalString() Method

Long class toOctalString() method: Here, we are going to learn about the toOctalString() method of Long class with its syntax and example. By Preeti Jain Last updated : March 20, 2024

Long 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 long type as an unsigned long in base 8.
  • toOctalString() method is a static method, it is accessible with the 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 long integer to an octal string.


    public static String toOctalString (long value);


  • long value – represents the long value to be converted.

Return Value

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


// Java program to demonstrate the example 
// of toOctalString (long value) method of Long class

public class ToOctalStringOfLongClass {
    public static void main(String[] args) {
        // Variables initialization
        long l1 = 10;
        long l2 = 20;
        long l3 = 30;
        long l4 = Long.MAX_VALUE;
        long l5 = Long.MIN_VALUE;

        // Long instance creation
        Long value = new Long(l1);

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

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

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

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

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

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

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

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


value.toOctalString(l2): 24
value.toOctalString(l3): 36
value.toOctalString(l4): 777777777777777777777
value.toOctalString(l5): 1000000000000000000000

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.