Java - Long getLong() 方法



描述

Java Long getLong(String nm) 方法确定具有指定名称的系统属性的 long 值。

声明

以下是 java.lang.Long.getLong() 方法的声明

public static Long getLong(String nm)

参数

nm - 这是属性名称。

返回值

此方法返回属性的 Long 值。

异常

从现有系统属性获取 Long 示例

以下示例演示了如何使用 Long getLong() 方法获取系统属性的 Long 值。我们创建了一个字符串变量并为其分配了一个有效的系统属性字符串。然后使用 getLong() 方法,我们打印系统属性的 Long 值。

package com.tutorialspoint;
public class LongDemo {
   public static void main(String[] args) {

      // determines the long value of the system property 
      String str = "sun.arch.data.model";
      System.out.println(Long.getLong(str));
   }
} 

输出

让我们编译并运行上述程序,这将产生以下结果:

64

从不存在的系统属性获取 Long 示例

以下示例演示了如何使用 Long getLong() 方法获取不存在的系统属性的 Long 值。我们创建了一个字符串变量并为其分配了一个无效的系统属性字符串。然后使用 getLong() 方法,我们检查系统属性的 Long 值,该值将打印为 null。

package com.tutorialspoint;
public class LongDemo {
   public static void main(String[] args) {

      // determines the long value of the system property 
      String str = "java";
      System.out.println(Long.getLong(str));
   }
} 

输出

让我们编译并运行上述程序,这将产生以下结果:

null
java_lang_long.htm
广告

© . All rights reserved.