You should always read docs first to see what a method does https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html
ifPresent
and isPresent
both check for null.
For instance if list is not null but is empty still System.out.println("here")
will be executed, You should check if list is empty with list.isEmpty()