Java Integer decode() methodThe 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 1Test it NowOutput: 81 276 -260 Example 2Test it NowOutput: Integer Number is = 555 Example 3This is an example in which we pass the String value and it shows NumberFormatException. Test it NowOutput: 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 TopicdivideUnsigned() Method
|