Which null-check is preferable?
Optional.ofNullable(port).ifPresent(settings::setPort);
or
if (port != null) {
settings.
Although, the snippet you have posted in the question is just a simple way to avoid the ugly null-check, yet is valid, correct and null-safe. Follow your personal preference in this case.
The real power of Optional are the following methods:
As example, let's say you want to get another value from port to add to the list and avoid the NPE if port is null:
Optional.ofNullable(port).map(port::getSomeValue).ifPresent(settings::setPort);
Moreover, please, avoid the following meaningless substitution of null-check I see often:
if (Optional.ofNullable(port).isPresent()) {
settings.setPort(port);
}