當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java OptionalDouble of(double)用法及代碼示例


of(double)方法有助於我們獲得OptionalDouble對象,該對象包含一個double值,該double值作為參數傳遞給此方法。

用法:

public static OptionalDouble of(double value)

參數:此方法接受一個double值作為參數,該值將設置為返回的OptionalDouble對象。


返回值:此方法返回一個帶有當前值的OptionalDouble。

以下示例程序旨在說明(double)方法:
示例1:

// Java program to demonstrate 
// OptionalDouble.of(double) method 
  
import java.util.OptionalDouble; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
  
        // Create a OptionalDouble instance 
        // using of() method 
        OptionalDouble opDouble 
            = OptionalDouble.of(45213.246); 
  
        // Get value of this OptionalDouble instance 
        System.out.println("OptionalDouble: "
                           + opDouble); 
    } 
}
輸出:
OptionalDouble: OptionalDouble[45213.246]

示例2:

// Java program to demonstrate 
// OptionalDouble.of(double) method 
  
import java.util.OptionalDouble; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
  
        // Create a OptionalDouble instance 
        // using of() method 
        OptionalDouble opDouble 
            = OptionalDouble.of(21438999); 
  
        // Get value of this OptionalDouble instance 
        System.out.println("OptionalDouble: "
                           + opDouble); 
    } 
}
輸出:
OptionalDouble: OptionalDouble[2.1438999E7]

參考文獻: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#of(double)



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 OptionalDouble of(double) method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。