Java equals() selection

Hi @sona11,
If you are using Java8 (or ablove) you can use Optional - for example:

boolean eq = Optional.ofNullable(aStringVariable)
            .map(s -> s.equals(MY_CONSTANT_STRING))
            .orElse(false);

And when the aStringValue is null there will no NullPointerException

I hope I understood the question correctly, does that help?

1 Like