Integer decode() Method in Java Last Updated : 05 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report It is often seen that any integer within (" ") is also considered as string, then it is needed to decode that into the integer. The main function of java.lang.Integer.decode() method is to decode a String into an Integer. The method also accepts decimal, hexadecimal, and octal numbers. Syntax : public static Integer decode(String str) Parameters: The method takes one parameter str of String data type and refers to the string needed to decode. Return Value: This method returns an Integer object which holds the int value represented by the string str. Exception: The method throws NumberFormatException, when the String contains an integer that cannot be parsed. Examples: Input: str_value = "50" Output: 50 Input: str_value = "GFG" Output: NumberFormatException Below programs illustrate the java.lang.Integer.decode() method. Program 1: java // Java program to demonstrate working // of java.lang.Integer.decode() method import java.lang.*; public class Gfg { public static void main(String[] args) { Integer int1 = new Integer(22); // string here given the value of 65 String nstr = "65"; // Returns an Integer object holding the int value System.out.println("Actual Integral Number = "+ int1.decode(nstr)); } } Output: Actual Integral Number = 65 Program 2: When string value is passed a NumberFormatException is thrown. java // Java program to demonstrate working // of java.lang.Integer.decode() method import java.lang.*; public class Gfg { public static void main(String[] args) { Integer int1 = new Integer(22); // String here passed as "geeksforgeeks" String nstr = "geeksforgeeks"; System.out.println("Actual Integral Number = "); System.out.println(int1.decode(nstr)); } } Output: Exception in thread "main" java.lang.NumberFormatException: For input string: "geeksforgeeks" 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(Gfg.java:15) Comment More infoAdvertise with us Next Article Integer doubleValue() Method in Java A ankita_chowrasia Follow Improve Article Tags : Misc Java Java-lang package Java-Functions Java-Integer +1 More Practice Tags : JavaMisc Similar Reads Integer hashCode() Method in Java The java.lang.Integer.hashCode() method of Integer class in Java is used to return the hash code for a particular Integer . Syntax: public int hashCode() Parameters : The method does not take any parameters. Return Value: The method returns a hash code integer value for this object, which is equal t 2 min read Integer doubleValue() Method in Java The doubleValue() method of Integer class of java.lang package is used to convert the value of the given Integer to a Double type after a widening primitive conversion and returns it. Syntax: public double doubleValue() Parameters: The method does not take any parameter. Return Value: This method re 1 min read Java Integer compare() method The compare() method of Integer class of java.lang package compares two integer values (x, y) given as a parameter and returns the value zero if (x==y), if (x < y) then it returns a value less than zero and if (x > y) then it returns a value greater than zero. Syntax : public static int compar 2 min read Integer floatValue() Method in Java floatValue() method of Integer class present inside java.lang package is used to convert the value of the given Integer to a float type after a widening primitive conversion which in general is mostly applicable when we want to truncate or rounding-off the integer value. The package view is as follo 2 min read Integer sum() Method in Java The java.lang.Integer.sum() is a built-in method in java that returns the sum of its arguments. The method adds two integers together as per the + operator. Syntax : public static int sum(int a, int b) Parameter: The method accepts two parameters that are to be added with each other: a : the first i 2 min read Java Integer compareTo() method The compareTo() method of Integer class of java.lang package compares two Integer objects numerically and returns the value 0 if this Integer is equal to the argument Integer; a value less than 0 if this Integer is numerically less than the argument Integer; and a value greater than 0 if this Intege 2 min read Like