13 Temmuz 2022 Çarşamba

OptionalDouble Sınıfı

Giriş
Açıklaması şöyle
An OptionalDouble object is one that can potentially contain a double number. Methods in the class can be used to work with the double value present in the object, or specify that there is no double contained at all.
getAsDouble metodu
Açıklaması şöyle
getAsDouble() is one of these methods, and it essentially returns the double value if there is one present. Otherwise, NoSuchElementException is thrown.
Örnek
Şöyle yaparız
OptionalDouble num = OptionalDouble.of(15.0);
System.out.println(num.getAsDouble());// Output: 15.0
of metodu
Örnek
Şöyle yaparız
OptionalDouble val = OptionalDouble.empty();
OptionalDouble val2 = OptionalDouble.of(15.0);

System.out.println("val2 >>");
System.out.println("A value is present: " + val2.isPresent());
System.out.println("Double contained: " + val2.getAsDouble());
System.out.println("Equal to 15: " + val2.equals(15.0));
System.out.println();
System.out.println("val >>");
System.out.println("A value is present: " + val.isPresent());
System.out.println("Double contained: " + val.getAsDouble());
/*
Output:
val2 >>
A value is present: true
Double contained: 15.0
Equal to 15: false
val >>
A value is present: false
NoSuchElementException
*/

Hiç yorum yok:

Yorum Gönder