We can do that with...first() method. It allows to not only get the first element but also to get a default object when iterable object is empty:
@Test
public void should_get_first_element() {
...
Get new posts, recommended reading and other exclusive information every week. SPAM free - no 3rd party ads, only the information about waitingforcode! Curious about the content ? Check some of already sent newsletters
You want to learn data engineering but have no idea where and how to start in this wide domain? Check if Become a Data Engineer can help you 💪