A

Admin • 825.56K Points
Coach

Q. How can you avoid a `NullPointerException` while using streams?

  • (A) Use empty lists only
  • (B) Use null-safe streams like `Optional.ofNullable()`
  • (C) Avoid using `stream()`
  • (D) Convert everything to primitive types

Explanation by: Admin
`Optional.ofNullable()` helps avoid null pointer exceptions when dealing with potentially null values.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.