java - How to check String values equal null? -


this question has answer here:

i'm new in java programming. have problem when have string variable equals null. when check condition on string error :

exception in thread "main" java.lang.nullpointerexception.

this code :

public class test {     static string a=null;     public static void main(string[] args) {         if(a.equals(null)){             system.out.println("null");         }     } } 

instead of a.equals(null) should doing a == null.

if(a == null) {     system.out.println("null"); } 

alternatively, can use stringutils check if string null or empty doing:

if(stringutils.isempty(a)) {     system.out.println("null"); } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -