Java Integer getInteger() method
The getInteger() method of Integer class determines the integer value of the system property with the given name.
Syntax`
public static Integer getInteger(String nm)
Parameters
The parameter ‘nm’ represents the property name.
Throws
The getInteger () method throws:
SecurityException- for the same reasons as System.getProperty
Return Value
This method returns the integer value of the property.
Example 1
public class JavaIntegerGetIntegerExample1 {
public static void main(String[] args) {
// it will give you an exception unless and until you have set the system property
String str="123";
int val=Integer.getInteger(str);
System.out.println(val);
}
}
Output
Exception in thread "main" java.lang.NullPointerException at com.TutorialAndExample.JavaIntegerGetIntegerExample1.main(JavaIntegerGetInteger Example1.java:6)
Example 2
public class JavaIntegerGetIntegerExample2 {
public static void main(String[] args) {
// determines the integer value of the system property with the given name
String str=" ";
System.setProperty(str,"123");
int val=Integer.getInteger(str);
System.out.println(val);
}
}
Output
123
Example 3
public class JavaIntegerGetIntegerExample3 {
public static void main(String[] args) {
// it gives an exception if value other than an integer is entered
String str="123 ";
System.setProperty(str,"reema@panda");
int val=Integer.getInteger(str);
System.out.println(val);
}
}
Output
Exception in thread "main" java.lang.NullPointerException at com.TutorialAndExample.JavaIntegerGetIntegerExample3.main(JavaIntegerGetInteger Example3.java:8)
