Java 8 optional | optional class | optional class interview questions | java 8 interview | okay java
Java 8 Optional class
Optional.empty()
Optional.of()
Optional.ofNullable()
.isPresent()
.ifPresent()
.get()
.orElse()
.orElseGet()
orElse v/s orElseGet()
.orElseThrow()
.filter()
.map()
.flatMap()
What is optional in java 8 ?
Optional is Final class in Java 8
to handle values as ‘available’ or ‘not available’ instead of checking null values.
What are the different ways to create an optional object
Optional.empty()
Optional.of()
Optional.ofNullable()
Optional.of() v/s Optional.ofNullable()
What is difference b/w Optional.of() and Optional.ofNullable() ?
Optional.of does not handle the "null" value , it gives null pointer exception.
.isPresent()
Boolean function
Returns true if there is a value present, otherwise false.
.get()
If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.
. ifPresent(consumer)
if a value is present, it invokes the specified consumer with the value, otherwise does nothing.
opStr2.ifPresent(s -> System.out.println(s.toUpperCase()));
. orElseThrow(supplier)
Returns the contained value, if present, otherwise throws an exception to be created by the provided supplier.
// orElseThrow
Optional < Integer > item = Optional.empty();
. filter(predicate)
If a value is present and the value matches a given predicate, it returns an Optional describing the value, otherwise returns an empty Optional.
// Filter - apply a predicate
Optional Integer age = Optional.of(20);
int a = age.filter(n -> n > 18).get();
System.out.println(a);
1. Java 8 new features
• Java 8 features | okay java | Java 8 ...
2. Java 8 functional interface part
• Java 8 functional interface part | fu...
3. Java 8 functional interface coding
• Java 8 functional interface coding | ...
4. Functional Interface prior to Java 8
• Functional Interface prior to Java 8 ...
5. Default methods in interface
• Default methods in interface | java 8...
6. Default methods Diamond Problem in java 8
• Default methods Diamond Problem in ja...
7. Java 8 lambda expression
• Java 8 lambda expression | okay java ...
8. Lambda expression variable scope interview questions
• Lambda expression variable scope inte...
9. Java 8 predicate functional Interface
• Java 8 predicate functional Interface...
10. Java 8 function interface
• Java 8 function interface | java 8 in...
11. Java 8 consumer functional interface
• Java 8 consumer functional interface ...
12. java 8 supplier functional interface
• java 8 supplier functional interface ...
13. Java 8 method reference
• Java 8 method reference okay java | J...
14. Java 8 optional class
• Java 8 optional class | java optional...
15. Java 8 stream pipeline flow
• Java 8 stream pipeline flow | java 8 ...
16. Java 8 stream api operations
• Java 8 stream api operations | java 8...
17. create java 8 stream
• create java 8 steam | stream.of | fun...
18. stream api - create java 8 streams
• java 8 stream stream api | generate i...
19. java 8 stream api- range v/s rangeclosed
• java 8 stream api | range v/s rangecl...
20. java 8 stream api - filter | collect
• java 8 stream api | filter | collect ...
21. java 8 stream api - map function distinct | filter
• java 8 stream api | map function | m...
22. java 8 stream api - flatmap
• java 8 stream api | flatmap | flatmap...
23. java 8 interview question - sort employee list using stream api function
• java 8 interview question | sort empl...
24. java 8 interview question - built in functional interfaces in java
• java 8 interview question | built in ...
25. Create Immutable class in Java
• Create Immutable class in Java | Writ...
26. what is a web service ?
• what is a web service ? | web service...
27. Watch Introduction to Microservices 08.50 Minutes
• okay java | introduction to microserv...
28. Watch Microservices components in one video 20 Minutes
• okayjava | microservices components |...
29. Watch How to Install Spring Tool Suite on Windows Machine
• okay java | install spring tool suite...
Subscribe and share okayjava
https://www.youtube.com/okayjava?sub_...
In questa pagina del sito puoi guardare il video online Java 8 optional class | java optional class interview questions | java 8 interview | okay java della durata di ore minuti seconda in buona qualità , che l'utente ha caricato okay java 13 maggio 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 13,985 volte e gli è piaciuto 290 spettatori. Buona visione!