Search code examples
javaperformanceif-statementconditional-statementsnotnull

Which is the best way to use not null condition,Whether direct condition or using utility methods?


I want to check the not null condition in many places ,So which way give the best performance..?

1.Whether if(object !=null){ ... }

2.Whether if(Util.isNotNull(object)){...}


Solution

  • The first way is a better way to proceed with

    if(object !=null){ ... }
    

    as it will use the short circuit evaluation.