Java.lang.Long 类

java.lang.Long.getLong()方法用于确定指定的系统属性的long值姓名。第一个参数被视为系统属性的名称。

如果没有具有指定名称的属性、指定名称为空或 null,或者属性没有正确的数字格式,则返回 null。

语法

public static Long getLong(String nm)

参数

nm 指定属性名称。

返回值

返回属性的 Long 值。

异常

抛出 SecurityException,原因与 System.getProperty 相同。

示例:

在下面的示例中,java.lang.Long.getLong() 方法返回具有给定名称的系统属性的 Long 值。

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //使用setProperty创建系统属性
    String x = "285";
    System.setProperty(x, "285");
    String y = "abc";
    System.setProperty(y, "abc");

    //打印x的Long值
    System.out.print("The Long value of x is: "); 
    System.out.println(Long.getLong(x));

    //打印y的Long值
    System.out.print("The Long value of y is: "); 
    System.out.println(Long.getLong(y));
  }
}

上述代码的输出将是:

The Long value of x is: 285
The Long value of y is: null