Java.lang.Integer.getInteger() 方法
描述
java.lang.Integer.getInteger(String nm, int val) 方法确定具有指定名称的系统属性的整数值。参数val为默认值 . 如果没有指定名称的属性,如果属性没有正确的数字格式,或者指定的名称为空或 null,则返回表示第二个参数的值的 Integer 对象。
声明
以下是 java.lang.Integer.getInteger() 方法的声明。
public static Integer getInteger(String nm, int val)
参数
nm − 这是属性名称。
val − 这是默认值。
返回值
该方法返回属性的整数值。
异常
NA
示例
下面的例子展示了 java.lang.Integer.getInteger() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class IntegerDemo {
public static void main(String[] args) {
/* returns the integer value of the system property and won't
print default specified value as specified system property exits */
String str = "sun.arch.data.model";
System.out.println(Integer.getInteger(str, 5));
/* returns default specified value as system property "abcd"
does not exist */
System.out.println(Integer.getInteger("abcd",5));
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
64 5

