Java.lang Package Classes

Java Long - toOctalString() Method



The java.lang.Long.toOctalString() method returns a string representation of the long argument as an unsigned integer in base 8.

Syntax

public static String toOctalString(long i)

Parameters

i Specify a long to be converted to a string.

Return Value

Returns the string representation of the unsigned long value represented by the argument in octal (base 8).

Exception

NA.

Example:

In the example below, the java.lang.Long.toOctalString() method returns a string representation of the long argument as an unsigned integer in base 8.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating long value
    long x = 25;
    long y = 31;
    long z = 111;

    //creating and printing string representation of 
    //argument in octal system.
    System.out.println("x in octal system is: " + Long.toOctalString(x)); 
    System.out.println("y in octal system is: " + Long.toOctalString(y)); 
    System.out.println("z in octal system is: " + Long.toOctalString(z));   
  }
}

The output of the above code will be:

x in octal system is: 31
y in octal system is: 37
z in octal system is: 157

❮ Java.lang - Long