Java.lang Package Classes

Java Integer - getInteger() Method

The java.lang.Integer.getInteger() method is used to determine the integer value of the system property with the specified name. The first argument is treated as the name of a system property.

The second argument is the default value. An Integer object that represents the value of the second argument is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or null.


public static Integer getInteger(String nm,
                                 int val)


nm Specify the property name.
val Specify the default value.

Return Value

Returns the Integer value of the property.


Throws SecurityException, for the same reasons as System.getProperty.


In the example below, the java.lang.Integer.getInteger() method returns the Integer value of the system property with the given name.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //creating system property using setProperty
    String x = "285";
    System.setProperty(x, "285");
    String y = "abc";
    System.setProperty(y, "abc");

    //printing the Integer value of x
    System.out.print("The Integer value of x is: "); 
    System.out.println(Integer.getInteger(x, 100)); 

    //printing the Integer value of y 
    System.out.print("The Integer value of y is: "); 
    System.out.println(Integer.getInteger(y, 100)); 

The output of the above code will be:

The Integer value of x is: 285
The Integer value of y is: 100

❮ Java.lang - Integer