[ORC_Java Prep] 1. Java SE 11 Certification

2021. 3. 29. 12:59Data science

반응형

1) Exam Overview

 

 

2) Prepare for an Exam 

3) How to approach Questions

해설)

1) Firstly, we are creating a list of strings. And we have a return statement. (List to Stream converting-> this does NOT mean that this the result will return a stream)

2) In the return statement, we filter.(Still stream, but it's empty as we don't have Bart in the list) 

3) We call findAny. (Any objects in the resulting stream - returns an optional)

4) 'Optional object' = a wrapper (instead of return a null value, gives you an optional as a layer of safety)

-> SO A is WRONG, B is CORRECT

5) the collection made out of List.of in Java is immutable. NOT allowed to add elements of the collection. 

-> SO C is WRONG

6) .get takes optional and returns whatever value it contains. But in this case, there is no Bart in the Collection. -> This means it's an exception.In the questions, it says "Complies exception-free code"  

-> D is WRONG

7) .orElse takes optional and returns whatever value it contains. In this case, rather than presenting 'no value'(Exception), throwing an alternative value("Not Found").

-> E is CORRECT

 

반응형