java.lang.Integer getInteger(String nm)

Description :

This java tutorial shows how to use the getInteger(String nm) method of Integer class under java.lang package. This method returns the Integer value of System.property that has been specified as method argument.

Method Syntax :

public static Integer getInteger(String nm)

Parameter Input :

DataType Parameter Description
String nm the system property key that we are interested in getting the value as an Integer object.

Method Returns :

The getString(String nm) method simply returns the value of the property key specified as method argument interpreted as an Integer object.

Compatibility Version :

Requires Java 1.0 and up

Exception :

N/A

Discussion :

The getInteger(String nm) method is static thus we should invoke it statically for example Integer.getInteger(String nm). This method simply returns the value of the property String specified as method argument. Normally if we get the one of the system property we would use System.getProperty(String key) and it would return a String value which corresponds to the key that is passed as method argument. On the getInteger(String nm) we do the same passing the String key value however the only difference is that this static method of Integer class interpret the result value to an Integer object. If the property value cannot be interpreted as an Integer, the getInteger(String nm) method returns null.

Make a note that there is an overloaded method which is the getInteger(string nm, int val). One way they would yield the same result if the val method parameter is null. Thus the following expression is true:

Integer.getInteger(String nm) = Integer.getInteger(String nm, null);

Java Code Example :

This java example source code demonstrates the use of getInteger(String nm) method of Integer class. Basically we get one value of System property to demonstrate the use of this method. And also we also set one custom property and then we get the same value using the Integer.getString(String nm) for us to further understand the behavior of this static method.

package com.javatutorialhq.java.examples;

import static java.lang.System.*;

/*
 * This example source code demonstrates the use of 
 * getInteger(String nm) method of Integer class.
 * Basically we check for int value of one of the custom property
 * and also the custom property that we have set
 */

public class IntegerGetIntegerString {

	public static void main(String[] args) {
		// Get one default system property
		out.println("Default property:"
				+ Integer.getInteger("sun.arch.data.model"));
		// set a custom property
		System.setProperty("test.integer", "100");
		// get the value of the custom property we set
		out.println("Custom Property:" + Integer.getInteger("test.integer"));

	}

}

Sample Output :

Running the getInteger(String nm) method example source code of Integer class will give you the following output

java integer getInteger(string nm) method example

java integer getInteger(string nm) method example

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :