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.