Java Long decode() method with Examples Last Updated : 05 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The java.lang.Long.decode() is a built in function in java that decodes a String into a Long. It accepts decimal, hexadecimal, and octal numbers. Syntax: public static Long decode(String number) throws NumberFormatException Parameter: number- the number that has to be decoded into a Long. Error and Exceptions: NumberFormatException: If the String does not contain a parsable long, the program returns this error. Returns: It returns the decoded string. Program 1: The program below demonstrates the working of function. java // Java program to demonstrate // of java.lang.Long.decode() method import java.lang.Math; class GFG { // driver code public static void main(String args[]) { // demonstration of function Long l = new Long(14); String str = "54534"; System.out.println("Number = " + l.decode(str)); } } Output: Number = 54534 Program 2: The program demonstrates the conversions using decode() function java // Java program to demonstrate // of java.lang.Long.decode() method import java.lang.Math; class GFG { // driver code public static void main(String args[]) { // demonstration of conversions String decimal = "10"; // Decimal String hexa = "0XFF"; // Hexa String octal = "067"; // Octal // convert decimal val to number using decode() method Integer number = Integer.decode(decimal); System.out.println("Decimal [" + decimal + "] = " + number); number = Integer.decode(hexa); System.out.println("Hexa [" + hexa + "] = " + number); number = Integer.decode(octal); System.out.println("Octal [" + octal + "] = " + number); } } Output: Decimal [10] = 10 Hexa [0XFF] = 255 Octal [067] = 55 Program 3: The program demonstrates error and exceptions. Java // Java program to demonstrate // of java.lang.Long.decode() method import java.lang.Math; class GFG { // driver code public static void main(String args[]) { // demonstration of errorand exception when // a non-parsable Long is passed String decimal = "1A"; // throws an error Integer number = Integer.decode(decimal); System.out.println("string [" + decimal + "] = " + number); } } Output: Exception in thread "main" java.lang.NumberFormatException: For input string: "1A" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.valueOf(Integer.java:740) at java.lang.Integer.decode(Integer.java:1197) at GFG.main(File.java:16) Comment More infoAdvertise with us Next Article Java Long decode() method with Examples gopaldave Follow Improve Article Tags : Misc Java Java-lang package Java-Functions java-Long +1 More Practice Tags : JavaMisc Similar Reads Charset canEncode() method in Java with Examples The canEncode() method is a built-in method of the java.nio.charset checks whether a particular charset supports encoding or not. Almost every charset can encode, except a few. Syntax: public boolean canEncode() Parameters: The function does not accepts any parameter. Return Value: The function retu 3 min read CharsetDecoder reset() method in Java with Examples The reset() method is a built-in method of the java.nio.charset.CharsetDecoder class which resets this CharsetDecoder and clears its internal state. Syntax: public final CharsetDecoder reset() Parameters: The function does not accepts any parameter. Return Value: The function returns this CharsetDec 1 min read CharsetEncoder reset() method in Java with Examples The reset() method is a built-in method of the java.nio.charset.CharsetEncoder resets this encoder, and clears all the internal states if there are any. It also resets charset-independent state and also invokes the implReset method in order to perform any charset-specific reset actions. Syntax: publ 2 min read Double hashCode() method in Java with examples The hashCode() method of Double class is a built-in method use to return the hashcode value of this Double object. Syntax: DoubleObject.hashCode() Parameters: It takes no parameters. Return Type: It returns an int value. The value returned is (int)(v^(v>>>32)) where v is a long variable equ 1 min read CharsetDecoder malformedInputAction() method in Java with Examples The malformedInputAction() method is a built-in method of the java.nio.charset.CharsetDecoder class which returns this decoder's current action for malformed-input errors. Syntax: public CodingErrorAction malformedInputAction() Parameters: The function does not accepts any parameter. Return Value: T 1 min read Like