Java Integer decode() methodLast Updated : 17 Mar 2025 The decode() method is a static method of Integer class under java.lang package. The main function of this method is to decode a string which is written in the form of (" ") into an integer value. The decode() method also accepts decimal, hexadecimal, and octal numbers. It is given by the following grammar: DecodableString:Signopt DecimalNumeral Signopt 0x HexDigits Signopt 0X HexDigits Signopt # HexDigits Signopt 0 OctalDigits Sign:This type of String will throw a NumberFormatException or represent a positive value. The result is negated if sign of the first character of the decodable String is minus. There are no whitespace characters are permitted in the String. SyntaxFollowing is the declaration of decode() method: Parameter:
Returns:The decode() method returns an Integer object which hold the int value represented by String nm. Exceptions:NumberFormatException - This method throws an exception if the String does not contain an integer which can be parsed. Compatibility Version:Java 1.2 and above Example 1Output: 81 276 -260 Example 2Output: Integer Number is = 555 Example 3This is an example in which we pass the String value and it shows NumberFormatException. Output: Exception in thread "main"java.lang.NumberFormatException: For input string: "JavaTpoint" 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 myPackage.DecodeMethodExample.main(DecodeMethodExample.java:8) Example 4Output: Enter a value to decode: 656 Result:656 Next TopicJava-integer-divideunsigned-method |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India