Java.lang.Integer.decode() Method
Advertisements
Description
The java.lang.Integer.decode() method decodes a String into an Integer. It accepts decimal, hexadecimal, and octal number.
Declaration
Following is the declaration for java.lang.Integer.decode() method
public static Integer decode(String nm) throws NumberFormatException
Parameters
nm -- This is the String to decode.
Return Value
This method returns an Integer object holding the int value represented by nm .
Exception
NumberFormatException -- if the String does not contain a parsable integer.
Example
The following example shows the usage of java.lang.Integer.decode() method.
package com.tutorialspoint;
import java.lang.*;
public class IntegerDemo {
public static void main(String[] args) {
Integer i = new Integer(10);
String str = "50";
/* returns an Integer object holding the int value represented
by string str */
System.out.println("Number = " + i.decode(str));
}
}
Let us compile and run the above program, this will produce the following result:
Number = 50