java.lang.Integer getInteger(String nm, Integer val)

Description :

This java tutorial shows how to use the getInteger(String nm, Integer val) method of Integer class under java.lang package. This method returns the Integer value of System.property that has been specified as method argument or if the property has not been found then the val specified will be returned instead.

Method Syntax :

public static Integer getInteger(String nm, Integer value)

Parameter Input :

DataType Parameter Description
String nm the system property key that we are interested in getting the value as an Integer object.
Integer val This is the value returned if the property were not found.

Method Returns :

The getString(String nm, Integer val) method simply returns the value of the property key specified as method argument interpreted as an Integer object and if not found the default value will be returned as determined by the val method argument.

Compatibility Version :

Requires Java 1.0 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of getInteger(String nm, Integer val) 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, Integer val) 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, int val) method of Integer class.
 * Basically we check for Integer 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(Integer.getInteger("java.vm.specification.vendor",
				new Integer(123)));
		// without default value
		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"));
		out.println("Custom Property:"
				+ Integer.getInteger("not.exist", new Integer(101)));

	}

}

Sample Output :

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

java integer getInteger(string nm, Integer val) method example

java integer getInteger(string nm, Integer val) method example

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :