Java lang Long.toOctalString() Method with Examples Last Updated : 19 Nov, 2020 Comments Improve Suggest changes Like Article Like Report The Java.lang.Long.toOctalString() function is a built-in function in Java that returns a string representation of the long argument as an unsigned integer in base 8. Syntax: public static int toOctalString(long num) Parameters: The function accepts a single mandatory parameter num, which is to be converted to a string. The parameter is of long data-type. Returns: The function returns a string representation of the long argument as an unsigned integer in base 8. Examples: Input : 16 Output : 20 Input : 1234 Output : 2322 Program to demonstrate the working of function: Java // Java program to demonstrate working // of java.lang.Long.toOctalString() method import java.lang.Math; class Gfg1 { // driver code public static void main(String args[]) { long l = 16; // returns the string representation of the unsigned int value // represented by the argument in octal (base 8) System.out.println("Octal string is " + Long.toOctalString(l)); l = 1234; System.out.println("Octal string is " + Long.toOctalString(l)); } } Output: Octal string is 20 Octal string is 2322 Program 2: The program below demonstrates the working function when a negative number is passed. Java // Java program to demonstrate // of java.lang.Long.toOctalString() method // negative number import java.lang.Math; class Gfg1 { // driver code public static void main(String args[]) { // when negative number is passed System.out.println("Hex is " + Long.toOctalString(-14)); } } Output: Hex is 1777777777777777777762 Errors and Exception: Whenever a decimal number or a string is passed as an argument, it returns an error message which says "incompatible types". Program 3: The program below demonstrates the working function when a string number is passed. Java // Java program to demonstrate // of java.lang.Long.toOctalString() method // string number import java.lang.Math; class Gfg1 { // driver code public static void main(String args[]) { // when string number is passed System.out.println("Hex is " + Long.toOctalString("14")); } } Output: prog.java:13: error: incompatible types: String cannot be converted to long System.out.println("Hex is " + Long.toOctalString("14")); Program 4: The program below demonstrates the working function when a decimal is passed. Java // Java program to demonstrate // of java.lang.Long.toOctalString() method // decimal number import java.lang.Math; class Gfg1 { // driver code public static void main(String args[]) { // when decimal number is passed System.out.println("Hex is " + Long.toOctalString(15.67)); } } Output: prog.java:13: error: incompatible types: possible lossy conversion from double to long System.out.println("Hex is " + Long.toOctalString(15.67)); Comment More infoAdvertise with us Next Article Java lang Long.toOctalString() Method with Examples gopaldave Follow Improve Article Tags : Misc Java Java-lang package Java-Functions java-math java-Long +2 More Practice Tags : JavaMisc Similar Reads Java.lang.Long.valueOf() method with examples Java.lang.Long.valueOf() is a built-in method in Java of lang class that returns a Long object holding the value extracted from a specified String S when parsed with the radix that is given in the second argument. The first argument is interpreted as representing a signed long in the radix specified 2 min read Java.lang.Short toString() method in Java with Examples toString(short) The static toString() method of java.lang.Short returns a new String object representing the specified short. The radix is assumed to be 10.This is a static method hence no object of Short class is required for calling this method. Syntax: public static String toString(short b) Param 2 min read OptionalLong of(long) method in Java with examples The of(long) method help us to get an OptionalLong object which contains a long value which is passed as a parameter to this method. Syntax: public static OptionalLong of(long value) Parameters: This method accepts a long value as parameter that will be set to the returned OptionalLong object. Retur 1 min read LongAccumulator toString() method in Java with Examples The java.LongAccumulator.toString() is an inbuilt method in java that returns the String representation of the current value of the LongAccumulator instance. Syntax: public String toString() Parameters: This method does not accepts any parameter. Return Value: This method returns the string represen 2 min read Optional toString() method in Java with examples The toString() method of java.util.Optional class in Java is used to get the string representation of this Optional instance. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns the string representation of this Optional instance. Below program 1 min read Byte toString() method in Java with examples The toString() method of Byte class is a built in method in Java which is used to return a String value. public String toString() Syntax: ByteObject.toString() Return Value: It returns a String object, the value of which is equal to the value of the ByteObject. Below is the implementation of toStrin 2 min read Year toString() method in Java with Examples The toString() method of Year class in Java is used to return the string representation of this Year object. Syntax: public String toString() Parameter: This method does not accepts any parameter. Return Value: It returns the string representation of this Year object. Below programs illustrate the t 1 min read Bidi toString() method in Java with Examples The toString() method of java.text.Bidi class is used to display this Bidi instance in string representation. Syntax: public String toString() Parameter: This method accepts nothing as parameter. Return Value: This method display internal state of bidi in string format. Below are the examples to ill 2 min read Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Like