21 lines
461 B
Java
21 lines
461 B
Java
|
// streams/OptionalBasics.java
|
||
|
import java.util.*;
|
||
|
import java.util.stream.*;
|
||
|
|
||
|
class OptionalBasics {
|
||
|
static void test(Optional<String> optString) {
|
||
|
if(optString.isPresent())
|
||
|
System.out.println(optString.get());
|
||
|
else
|
||
|
System.out.println("Nothing inside!");
|
||
|
}
|
||
|
public static void main(String[] args) {
|
||
|
test(Stream.of("Epithets").findFirst());
|
||
|
test(Stream.<String>empty().findFirst());
|
||
|
}
|
||
|
}
|
||
|
/* Output:
|
||
|
Epithets
|
||
|
Nothing inside!
|
||
|
*/
|