java.lang.Integer.getInteger(String nm, int val)%uA0方法确定具有指定名称的系统属性的整数值。参数val为默认值。如果有指定名字的属性,如果属性不具有正确的数字格式,或者指定名称为空或null,或一个Integer对象,表示第二个参数的值被返回。
声明
以下是java.lang.Integer.getInteger()方法的声明
public static Integer getInteger(String nm, int val)
参数
-
nm%uA0-- 这是属性名。
-
val%uA0-- 这是缺省值。
返回值
此方法返回属性的整数值。
异常
-
NA
例子
下面的例子显示java.lang.Integer.getInteger()方法的使用。
package com.yiibai import java.lang.* public class IntegerDemo { public static void main(String[] args) { /* returns the integer value of the system property and won&apost 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