Home »
Java programming language
Java Long class toOctalString() method with example
Long class toOctalString() method: Here, we are going to learn about the toOctalString() method of Long class with its syntax and example.
Submitted by Preeti Jain, on October 13, 2019
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.
Syntax:
public static String toOctalString (long value);
Parameter(s):
- 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.
Example:
// 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);
}
}
Output
value.toOctalString(l2): 24
value.toOctalString(l3): 36
value.toOctalString(l4): 777777777777777777777
value.toOctalString(l5): 1000000000000000000000
TOP Interview Coding Problems/Challenges