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.toBinaryString() method with Examples The java.lang.Long.toBinaryString() method returns a string representation of the long argument as an unsigned integer in base 2. It accepts an argument in Long data-type and returns the corresponding binary string. Syntax: public static String toBinaryString(long num) Parameters : The function acce 3 min read 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 Locale toString() Method in Java with Examples The toString() method of Locale class in Java is used to return a string representation of this locale. Each element i.e., the language, country or the variant of the locale is separated by underbars Syntax: LOCALE.toString() Parameters: This method does not take any parameters. Return Value: This m 1 min read LongAdder toString() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.toString() is an inbuilt method in Java that returns the String representation of this LongAdder. When the object of the class is created its initial value is zero. Syntax: public String toString() Parameters 2 min read Level toString() method in Java with Examples The toString() method of java.util.logging.Level is used to get the string value which represents this Level.This method returns a string representation of this Level. Syntax: public String toString() Parameters: This method accepts nothing. Return: This method returns a string representation of thi 1 min read Java lang Integer.toHexString() Method with Examples The Java.lang.Integer.toHexString() is a built-in function in Java which returns a string representation of the integer argument as an unsigned integer in base 16. The function accepts a single parameter as an argument in Integer data-type. Syntax : public static String toHexString(int num) Paramete 3 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 Matcher toString() method in Java with Examples The toString() method of Matcher Class is used to get the String representation of this matcher. This method is derived from the Object Class and behaves in the similar way. Syntax: public String toString() Parameters: This method takes no parameters. Return Value: This method returns a String value 2 min read Like