如果存在Double值,則hashCode()方法可幫助我們獲取該值的哈希碼;如果OptionalDouble對象中不存在Double值,則為0(零)。
用法:
public int hashCode()
參數:此方法接受不接受任何參數。
返回值:此方法返回當前值的哈希碼值;如果不存在任何值,則返回0。
以下示例程序旨在說明hashCode()方法:
示例1:
// Java program to demonstrate
// OptionalDouble.hashCode() method
import java.util.OptionalDouble;
public class GFG {
public static void main(String[] args)
{
// create a OptionalDouble instance
OptionalDouble opDouble
= OptionalDouble.of(253255.432525);
System.out.println("OptionalDouble: "
+ opDouble.toString());
// get hashCode value using hashCode()
System.out.println("HashCode value: "
+ opDouble.hashCode());
}
}
輸出:
OptionalDouble: OptionalDouble[253255.432525] HashCode value: 885080309
示例2:
// Java program to demonstrate
// OptionalDouble.hashCode() method
import java.util.OptionalDouble;
public class GFG {
public static void main(String[] args)
{
// create a OptionalDouble instance
OptionalDouble opDouble
= OptionalDouble.empty();
System.out.println("OptionalDouble: "
+ opDouble.toString());
// get hashCode value using hashCode()
System.out.println("HashCode value: "
+ opDouble.hashCode());
}
}
輸出:
OptionalDouble: OptionalDouble.empty HashCode value: 0
參考文獻: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#hashCode()
相關用法
- Java OptionalDouble equals()用法及代碼示例
- Java OptionalDouble orElseGet()用法及代碼示例
- Java OptionalDouble isPresent()用法及代碼示例
- Java OptionalDouble empty()用法及代碼示例
- Java OptionalDouble ifPresentOrElse()用法及代碼示例
- Java OptionalDouble toString()用法及代碼示例
- Java OptionalDouble orElseThrow()用法及代碼示例
- Java OptionalDouble getAsDouble()用法及代碼示例
- Java OptionalDouble of(double)用法及代碼示例
- Java OptionalDouble stream()用法及代碼示例
- Java OptionalDouble orElse(double)用法及代碼示例
- Java OptionalDouble ifPresent(DoubleConsumer)用法及代碼示例
- Java OptionalDouble orElseThrow(Supplier)用法及代碼示例
- Java Set hashCode()用法及代碼示例
- Java Map hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 OptionalDouble hashCode() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。