目录

static Integer getInteger(String nm, int val)

描述 (Description)

java.lang.Integer.getInteger(String nm, int val)方法确定具有指定名称的系统属性的整数值。参数val是默认值。 如果没有指定名称的属性,如果属性没有正确的数字格式,或者指定的名称为空或null,则返回表示第二个参数值的Integer对象。

声明 (Declaration)

以下是java.lang.Integer.getInteger()方法的声明

public static Integer getInteger(String nm, int val)

参数 (Parameters)

  • nm - 这是属性名称。

  • val - 这是默认值。

返回值 (Return Value)

此方法返回属性的Integer值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.Integer.getInteger()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018